2012-06-23 92 views
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); 

回答

0

我建議你試試你在另一臺服務器\本地機器上的代碼,以確保它不是當前的庫安裝問題。

+0

: - 好的,我會在另一臺機器上試用 – user1476767