我正在尝试使用此脚本上传图片:
$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($width,$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);
我希望图像尺寸为130x130像素。现在我得到的是一个带有黑色空格的img,甚至还有一点点..
现在我该如何让它以正确的方式运作?
答案 0 :(得分:4)
您在imagecopyresampled调用中交换了宽度和高度参数。尝试交换$ width和$ height。