php image thumb generator在此图像上给出错误

时间:2012-11-11 12:32:10

标签: php image thumbnails phpthumb

我正在使用以下功能来创建图像大拇指,但由于某种原因,它不适用于以下图像:http://images.fanpop.com/images/image_uploads/zebra-zebras-52796_800_600.jpg

任何人都可以找出原因吗?

这是功能:

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);
  }

0 个答案:

没有答案