ArmeniaH
ArmeniaH

Reputation: 753

PHP imagecreatefromjpeg and imagecopy creates Pixelate and very poor quality on images

After using this code (just the part working with images)

$image = imagecreatefromjpeg($filename);
$new_width = $thumbnail_width;
$new_height = $thumbnail_height;
$start_width = 0;
$start_height = 0;
$start_width = ($thumbnail_width - $image_params[0]) / 2;
$start_height = ($thumbnail_height - $image_params[1]) / 2;
imagecopy($image_res, $image, $start_width, $start_height, 0, 0, $image_params[0], $image_params[1]);

Im getting very very poor pixelate result, you can see it here enter image description here

And here is the original image

enter image description here

PHP Version 5.3.18

GD Version bundled (2.0.34 compatible)

Using GD is a must for me. This example is working very good on many servers, but on some i get this terrible result, and i want to know the reason.

Any help please ?

Upvotes: 2

Views: 5716

Answers (2)

Umar Khan
Umar Khan

Reputation: 11

You need to specify quality percentage in imagejpeg(). Also, you could use imagecopyresampled() instead of imagecopy().

imagecopyresampled($new_image,$old_image,0,0,0,0,$new_width,$new_height,$image_width,$image_height);
imagejpeg($new_image,$image,100);

Upvotes: 1

fdrv
fdrv

Reputation: 890

I have solved same problem when specify % of quality.

imagejpeg($im, 'watemark.jpg', 100);

or 75 for lower etc.

http://php.net/manual/en/function.imagejpeg.php

Upvotes: 6

Related Questions