上传这张照片并调整大小后,我注意到它的质量变得有点模糊......为什么会发生这种情况?我有足够的空间,所以还有什么问题?
原来的,
调整大小后,
但是我上传的其他图片完全没有问题。为什么只发生在这张照片上?
会不会是下面的调整大小功能造成的?
function resize_image($image,$width,$height,$scale)
{
# Calculating proportionality
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
$imageType = image_type_to_mime_type($imageType);
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
# Loading image to memory according to type
switch($imageType)
{
case "image/gif":
$source = imagecreatefromgif($image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source = imagecreatefromjpeg($image);
break;
case "image/png":
case "image/x-png":
$source = imagecreatefrompng($image);
break;
}
# This is the resizing/resampling/transparency-preserving magic
if ( ($imageType == "image/gif") || ($imageType == "image/png") )
{
$transIndex = imagecolortransparent($source);
if($transIndex >= 0)
{
$transcol = imagecolorsforindex($source, $transIndex);
$transIndex = imagecolorallocatealpha($newImage, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
imagefill($newImage, 0, 0, $transIndex);
imagecolortransparent($newImage, $transIndex);
}
elseif ($imageType == "image/png" || $imageType == "image/x-png")
{
imagealphablending($newImage, false);
$color = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
imagefill($newImage, 0, 0, $color);
imagesavealpha($newImage, true);
}
}
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
# Writing image according to type to the output destination
switch($imageType)
{
case "image/gif":
imagegif($newImage,$image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($newImage,$image,90);
break;
case "image/png":
case "image/x-png":
imagepng($newImage,$image);
break;
}
chmod($image, 0777);
return $image;
}