PHP thumbnail creation method creates low quality thumbnails

I am using the following method to create thumbnails of uploaded jpg images [see code below]. problem is, the quality of the thumbnails is sub-par. [see attached files].

Is there a way to specify the quality of the images as they are converted to thumbnails using php?

the attached files for reference all contain the following characteristics:
resolution: 72 dpi
color depth: 8 bits / channel

the files represent the following:

orginal.jpg = the original file before upload
phpthumb.jpg = the thumbnail version created by the php script attached
psdthumb.jpg = the thumbnail version created by photoshop with quality set to 100

Let me know if there is a way to increase the output quality of the thumbnail via the code i am using.
$new_width = 100; // Fix the width of the thumb nail images
 //$n_height=100; // Fix the height of the thumb nail imaage

 $tsrc = "uploads/thumbs/".$newname; // Path where thumb nail image will be stored

 $img = imagecreatefromjpeg("uploads/".$newname);
 $width = imagesx($img); // Original picture width is stored
 $height = imagesy($img); // Original picture height is stored
 $new_height = floor( $height * ( $new_width / $width ) );
 $newimage=imagecreatetruecolor($new_width,$new_height);
 imagecopyresized($newimage,$img,0,0,0,0,$new_width,$new_height,$width,$height);
 imagejpeg($newimage,$tsrc);
 chmod("$tsrc",0777);

Open in new window

original.jpg
phpthumb.jpg
psdthumb.jpg
jsvb1977Asked:
Who is Participating?
 
hernst42Commented:
You could use http://www.php.net/manual/en/function.imagecopyresampled.php instead of imagecopyresized which should have better quality (http://www.php.net/manual/en/function.imagecopyresized.php)
0
 
jsvb1977Author Commented:
thanks, i will check it out and report back with my success or failure -- and i apologize for the information on the sign. I did not think before i posted.
0
 
jsvb1977Author Commented:
perfect. thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.