我正在处理图像上传并使用 PHP 将文件保存在服务器上。我想将图像大小调整为 256px x 256px,我正在使用以下代码,但最终图像不是 256px x 256px 有人可以提供任何建议吗?
$promo_image = $_FILES['promo_image']['name'];
if($promo_image != "") {
$ext = pathinfo($promo_image, PATHINFO_EXTENSION);
$promolink = "uploads/Image/".uniqId().uniqId().uniqId().".".$ext;
list($width, $height) = getimagesize($_FILES['promo_image']['tmp_name']);
if(strtolower($ext) == "png")
$original = imagecreatefrompng($_FILES['promo_image']['tmp_name']);
else
$original = imagecreatefromjpeg($_FILES['promo_image']['tmp_name']);
$resized = imagecreatetruecolor(256,256);
imagecopyresampled($resized, $original, 0, 0, 0, 0,256 ,256, $width, $height);
if(strtolower($ext) == "png")
imagepng($resized, $promolink);
else
imagejpeg($resized, $promolink);
move_uploaded_file($_FILES['promo_image']['tmp_name'], $promolink);
}