Hello, I'm trying to resize images in php to make thumbs... The resize goes ok, but the quality of the resized image is very bad, although i set the jpg quality to 100. I use this code to resize: ... //create medium thumb version $new_width = floor($mediumthumbscale*$imgwidth); $new_height = floor($mediumthumbscale*$imgheight); //Create a new temporary image $tmp_img = imagecreatetruecolor($new_width, $new_height); //Copy and resize old image into new image imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $imgwidth, $imgheight); imagejpeg($tmp_img, $imgthumbpath.$mediumimagefilename,100); ... PHP: So the sizes are all correct and the thumb file gets created, but the quality is much poorer than when i do the resize manually in photoshop for example. Does anyone have an idea what the problem is here ?
Sure, i attached both results. The left one is the result with PHP, the right one is the result when i manually resize in photoshop or fireworks. The right one is much better and even 4 times smaller in size...
the problem is you are using the wrong function here - I suggest that you consider using imagecopyresampled() rather than imagecopyresized() A couple of snippets from the PHP online documentation should clarify this for you. imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity. imagecopyresized() copies a rectangular portion of one image to another image. dst_image is the destination image, src_image is the source image identifier. If the source and destination coordinates and width and heights differ, appropriate stretching or shrinking of the image fragment will be performed. You are currently stretching or shrinking the image and ending up with cr*p - if you resampled the image you would not have this problem.
I currently use phpThumb() and it works great for my needs on my site http://www.pointrelevance.com. I tried building a function from scratch but decided not to try to re-invent the wheel when my initial results were pretty crappy.
It's not that complicated to do it manually. What does php_thumb do ? Does it have any special functionalities ?
phpThumb() has a LOT of special functionalities. http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php