开发者

Image upload makes images with black spaces

开发者 https://www.devze.com 2023-01-23 15:29 出处:网络
I\'m trying to upload an image using this script: $photoName = $uploadedPhoto[\"name\"]; $photoType = $uploadedPhoto[\"type\"];

I'm trying to upload an image using this script:

 $photoName = $uploadedPhoto["name"];
 $photoType = $uploadedPhoto["type"];
 $photoSize = $uploadedPhoto["size"];
 $photoTemp = $uploadedPhoto["tmp_name"];
 $photoError = $uploadedPhoto["error"];    

 $ext=substr($photoName, strripos($photoName, '.'), strlen($photoName)); 

 if(!strcmp(".jpg",$ext) || !strcmp(".jpeg",$ext)) {
     $src_img=imagecreatefromjpeg($photoTemp);
 }

 if(!strcmp(".png",$ext)) {
     $src_img=imagecreatefrompng($photoTemp);
 }

 list($widt开发者_运维知识库h,$height)=getimagesize($photoTemp); 

 $dst_img=ImageCreateTrueColor(130, 130);

 imagecopyresampled($dst_img,$src_img,0,0,0,0, 130, 130,$height,$width); 

 if(!strcmp(".png",$ext))
    $imageCreated = imagepng($dst_img, $newImage['dir']."/".$newImage['newName'].$ext); 
 else
    $imageCreated = imagejpeg($dst_img,$newImage['dir']."/".$newImage['newName'].$ext); 

 imagedestroy($dst_img); 
 imagedestroy($src_img); 

And I want the image to be size of 130x130 px. Now what I get is an img with a black spaces and even cut a bit..

Image upload makes images with black spaces

Now how do I make it work the right way?


You have your width and height parameters swapped on the imagecopyresampled call. try swapping $width and $height.

0

精彩评论

暂无评论...
验证码 换一张
取 消