After uploading and resizing this photo, i noticed the quality of it become slightly blurry... why does this happen? I have enough space so what else could be the problem?
original,
after resizing,
But other pictures that I uploaded have no problem at all. Why does it happen to this picture only?
Would it be caused by the resizing function below?
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;
}
Jpeg is a format which is optimized for compressing photographies. In images such as the ones you show, the artifacts are far more noticeable than normal. I suggest you change the quality level on this line:
imagejpeg($newImage,$image,100);
Another option would be to save the image in png.