Image upload makes images with black spaces
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..
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.
精彩评论