views:

49

answers:

2

im taking image uploads on a website and changing the images to thumbnails that fit onto a 100 x 100 white square. the problem is that the images look like they dont anti-alias properly. images sized down in photoshop look smooth, but these look crunchy, like super sharpened.

take a look at these samples, showing full size on the left and thumbnails on the right (view at 100%). the photo comes out looking ridiculously sharpened, but a lot of people might not be bothered by it. the drawing though is waaay unacceptable. those curved lines just dont anti-alias at all and become dotted lines.

im using imagejpg(), and the jpg quality i choose has no effect on the crunchiness. heres some of the code surrounding it:

$tmp_img = imagecreatetruecolor( $maxSize, $maxSize );
$white = ImageColorAllocate ($tmp_img, 255, 255, 255);
ImageFill($tmp_img, 0, 0, $white);
imagecopyresized( $tmp_img, $img, $offsetx, $offsety, 0, 0, $new_width, $new_height, $width, $height );
$thumbFullPath = "{$pathToThumbs}/{$filenameNoExtension}.jpg";
imagejpeg( $tmp_img, $thumbFullPath, 90 );

any ideas? is this normal? thanks!

+3  A: 

change the last line to:

imagejpeg( $tmp_img, $thumbFullPath, 100 );

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

Also, try using imagecopyresampled() rather than imagecopyresized()

see: http://us4.php.net/manual/en/function.imagecopyresampled.php

jordanstephens
There won't be much of a difference between 90 and 100. Besides, I think it's more the scaling operation than the save operation that wastes the result. Also, OP said changing the quality doesn't enhance anything.
zneak
right, but it may help...10%... `imagecopyresampled()` has worked wonders for me in the past.
jordanstephens
agree, "try using imagecopyresampled() rather than imagecopyresized()"
Peter Perháč
@OP If it's not solved by this, please show some example images.
Pekka
i will give that a try a bit later, when ive patted down the current set of flames burning my desk. THANKS SO MUCH - imagecopyresampled() sounds promising!
owen
i couldnt resist trying it real quick, AND IT WORKS! you guys roooooocckckkk. kinda makes me wonder why anyone would use imagecopyresized, or why it even exists. thanks!
owen
imagecopyresized probably use simple nearest neighbor sampling that gives low quality. More precise scaling algorithms like imagecopyresampled apply low pass filters (blur) before sub-sampling this makes hi frequency spikes disappear in tumbnail.
Ross
+2  A: 

You may want to try imagecopyresampled instead of imagecopyresized. It's slower but uses a more sophisticated algorithm for determining the colour of every pixel in the new image.

Kris