0

Hi, I have a function that I use within my upload script that creates a thumbnail of each image that is uploaded (using php's GD library). The problem is, the thumbnails look absolutely horrible. They are not so much distorted, but just VERY blurry. Here is my function that is creating the thumbnails:

function create_thumb($pathToImage, $pathToThumb, $thumbWidth)
		    {
		    $img = imagecreatefromjpeg($pathToImage);
		    $width = imagesx($img);
		    $height = imagesy($img);
		    $new_width = $thumbWidth;
		    $new_height = floor($height * ($thumbWidth / $width));
		    $tmp_img = imagecreatetruecolor($new_width, $new_height);
		    imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
		    imagejpeg($tmp_img, $pathToThumb);
	      	    imagedestroy($tmp_img);
		    imagedestroy($img);
		    }
		    create_thumb('uploads/' . $name, 'uploads/thumbs/' . $name, 100);
                  echo "1";
              }

I have googled about this, and everything I read just tells me to make sure I have the newest version of the GD library, to use imagecopyresample (instead of imagecopyresize) and to use imagecreatetruecolor (instead of imagecreate). Which, as you can see, I do use all of those.

Any help is appreciated!

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by dschuett
0

pritaeas,

Thanks! That actually helped quite a bit. However, they still are a little blurry. - And this is for a photographer's website. Is there a reason why the thumbnails of the pictures that are portrait instead of landscape (the pics that are more tall than they are wide) are absolutely crystal clear! - but the landscape pics have a blur to them???

Thanks for your help!

0

From your code I read that you set the new width to 100px. That would mean that the landscape photos are reduced more than the portrait ones. That would explain why they are more clear. I suggest you find a percentage in which both types are clear, and use that instead of setting it to a fixed 100px.

Edited by pritaeas: n/a

0

Wow, I'm an idiot...I TOTALLY forgot that before I got this GD function working i was setting the height of the images in my gallery hard coded when I display each image. haha. Everything works GREAT now!

Thanks again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.