Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Looking for GDImage script...anyone know about this?

    Hi... I'm pulling my hair out trying to find a page I saw a while back and wasn't smart enough to put into my bookmarks...

    It was a guy who had made a script using PHP and the GD library which took a group of images and calculated the best way to fit them into a single block.

    For example if you have a bunch of random images with different dimensions, it will resize them to fit perfectly into a 500x500 square (etc). Does anyone have any idea what this is called or the page where I could find it??

    Thank you...

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    I'll see if i can dig something up for you
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    This function will return an array of your dimensions that are in proportion and no sides greater than that passed to the function as the $new_h parameter

    PHP Code:
    function get_dims($src_img,$new_h)
    {
     
    // A small function to ensure that the width and height of the thumbnails are no larger than 200px
        
    $new_w=$new_h;
            
    $size=getimagesize($src_img);
        
    $old_x=$size[0];
        
    $old_y=$size[1];
        if (
    $old_x $old_y
        {
            
    $thumb_w=$new_w;
            
    $thumb_h=$old_y*($new_h/$old_x);
        }
        if (
    $old_x $old_y
        {
            
    $thumb_w=$old_x*($new_w/$old_y);
            
    $thumb_h=$new_h;
        }
        if (
    $old_x == $old_y
        {
            
    $thumb_w=$new_w;
            
    $thumb_h=$new_h;
        }
        
    $size[0]=$thumb_w;$size[1]=$thumb_h;
        
        return 
    $size;
        

    To call this function simply use

    PHP Code:
    $size=get_dims($img_link,500); 
    Now you have got your dimensions you can use phpThumb_1.7.4.zip I even hosted this for you to download http://cybadev.co.uk/phpThumb_1.7.4.zip

    Once downloaded extract and put the whole folder in your document root
    Then you can call to it like so

    PHP Code:
    echo'
    <img src="phpThumb.php?src='
    .$img_link.'&w='.$size[0].'&h='.$size[1].'" />'
    for a more detailed demo of phpthumb use this link
    http://phpthumb.sourceforge.net/
    You can not say you know how to do something, until you can teach it to someone else.

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your help.

    However, the script (program? I remember it had a name) I'm looking for doesn't use a set pixel value, it calculates that dynamically based on the best way that the images fit together... sort of like Tetris... if you can picture that...

    I remember that the calculations were quite complicated. It wouldn't be something that could be easily duplicated.

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    I see. Probably quite tough but very possible. Let me know if you find it
    Last edited by timgolding; 07-04-2007 at 10:51 AM.
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •