0

这是我用来调整图像大小的脚本。

我的问题是这个脚本会生成负片(比如负片[只有 .png 文件])。哪里/什么问题?

我使用 GD 库重新调整图像大小,但得到了相同的结果。

       $dir = "../images/sliderimages/";
       $photo = $_FILES['slid_image_upload']['name'];
       $tmp_name = $_FILES['slid_image_upload']['tmp_name'];
       $filename = $dir.$photo;
   $dir_thm = "../images/thm_sliderimages/";
   $thm_filename = $dir_thm.'thm_'.$photo;

       /************Resizing the image***************/


       $size = getimagesize($tmp_name);

       $width = $size[0];

       $height = $size[1];

       $newheight = 200;
       $newwidth = 420;

   $newheight_thm = 50;
       $newwidth_thm = 80;

       $tmp=imagecreatetruecolor($newwidth,$newheight);
       $tmp_thm=imagecreatetruecolor($newwidth_thm, $newheight_thm);
       if($size[2] == IMAGETYPE_GIF)

       {

        $src = imagecreatefromgif($tmp_name);

        imagecopyresampled($tmp,$src, 0,0,0,0, $newwidth, $newheight, $width, $height);
        imagecopyresampled($tmp_thm, $src, 0,0,0,0, $newwidth_thm, $newheight_thm, $width, $height);
        imagegif($tmp,$filename,100);
        imagegif($tmp_thm,$thm_filename,100);

       }

       elseif($size[2] == IMAGETYPE_JPEG)

       {

        $src = imagecreatefromjpeg($tmp_name);

        imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
        imagecopyresampled($tmp_thm, $src, 0,0,0,0, $newwidth_thm, $newheight_thm, $width, $height);
        imagejpeg($tmp,$filename,100);
        imagejpeg($tmp_thm,$thm_filename,100);
       }

       elseif($size[2] == IMAGETYPE_PNG)

       {

        $src = imagecreatefrompng($tmp_name);

        imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
        imagecopyresampled($tmp_thm, $src, 0,0,0,0, $newwidth_thm, $newheight_thm, $width, $height);
        imagepng($tmp,$filename,9);
        imagepng($tmp_thm,$thm_filename,9);

       }
       imagedestroy($src);

       imagedestroy($tmp);
4

1 回答 1

0

我建议您尝试在另一台服务器\本地机器上编写代码,以确保这不是当前的库安装问题。

于 2012-06-23T12:52:10.230 回答