1

I'm using the following function to create image thumbs, but for some reason it doesn't work on the following image: http://images.fanpop.com/images/image_uploads/zebra-zebras-52796_800_600.jpg

Can anyone figure out why?

Here's the function:

function make_thumb($img_name,$filename,$new_w,$new_h)
  {

        //get image extension.
        $ext=getExtension($img_name);
        //create new image using the appropriate function from gd library
        if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext) || !strcmp("JPEG",$ext) || !strcmp("JPG",$ext))
        $src_img=imagecreatefromjpeg($img_name);

        if(!strcmp("gif",$ext) || !strcmp("GIF",$ext))
        $src_img=imagecreatefromgif($img_name);

        if(!strcmp("png",$ext) || !strcmp("PNG",$ext))
        $src_img=imagecreatefrompng($img_name);

        //gets the dimmensions of the image
         $old_x=imageSX($src_img);
         $old_y=imageSY($src_img);

        //  calculate dimensions for the thumbnail

        $ratio1=@$old_x/$new_w;
        $ratio2=@$old_y/$new_h;

        if($ratio1>$ratio2) {
        $thumb_w=$new_w;
        $thumb_h=$old_y/$ratio1;
        }
        else {
        $thumb_h=$new_h;
        $thumb_w=$old_x/$ratio2;
        }
        /****  start  Customization  *********************/
        if($new_w > $old_x && $new_h > $old_y)
        {
          $thumb_w=$old_x;
          $thumb_h=$old_y;
        } 
        /****  end  Customization  *********************/


        // create new image with the new dimensions
        $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

        // resize 
        imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

        // output the created image to the file. Now we will have the thumbnail in the file named by $filename
        if(!strcmp("png",$ext))
        imagepng($dst_img,$filename);
        elseif(!strcmp("gif",$ext))
        imagegif($dst_img,$filename);
        elseif(!strcmp("GIF",$ext))
        imagegif($dst_img,$filename);
        elseif(!strcmp("PNG",$ext))
        imagegif($dst_img,$filename);
        else
        imagejpeg($dst_img,$filename);

        //destroys source and destination images.
        imagedestroy($dst_img);
        imagedestroy($src_img);
  }
Phil
  • 1,719
  • 6
  • 21
  • 36
  • Have you see [phpThumb()](http://phpthumb.sourceforge.net/) ? It does so much more or there any particular objective apart from thumb creation ??? – Baba Nov 11 '12 at 12:35
  • 1
    Because this is a web page not an image! The url looks like an image but when you click you'll be redirected to a web page. – Oras Nov 11 '12 at 13:19
  • all i was saying is use `phpThumb` to replace `make_thumb` – Baba Nov 11 '12 at 14:15

0 Answers0