Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP GD: Bad quality on resize?

Tags:

php

I dont like the resized image i get out,

imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext", 100);

I added 100 in ImageJpeg, because i wish to improve the quality, but it didnt get any better.

How can i improve the quality on resized images/thumbnails

like image 909
Karem Avatar asked Sep 01 '10 10:09

Karem


3 Answers

Try using imagecopyresampled instead. That does interpolation, which will make things look a lot nicer.

like image 53
Matt Gibson Avatar answered Nov 15 '22 07:11

Matt Gibson


Since PHP 5.5, you can use imagesetinterpolation to determine the way your images are interpolated during transformations (typically, scaling and resampling, but also rotations, etc.).

See http://php.net/manual/en/function.imagesetinterpolation.php

For image downsampling, you probably want to use the IMG_SINC algorithm, it tends to give crisper results. For rotation as well.

For upsampling, IMG_BICUBIC_FIXED, IMG_GENERALIZED_CUBIC and IMG_QUADRATIC might give the better results. Ultimately you'll have to test them: set this option on newly created image resources as soon as possible, combine it with the high quality flag when saving jpegs, and you should be pretty free from artifacts when using GD.

like image 20
Mauro Colella Avatar answered Nov 15 '22 07:11

Mauro Colella


try using imagecopyresampled instead.

like image 45
aularon Avatar answered Nov 15 '22 08:11

aularon