I am currently writing a script for a client of mine that allows them to upload up to five images at a time when they add a new record to a MySQL table. This is the first time I have ever really dealt with the php image functions (gd2).
What happens is the images are uploaded via a page, and then processed to make thumbnail images out of each one. The thumbnail images are resized to 100 pixels wide, and 150 pixels high. Now, the actual resizing and saving works, thanks to a snippet I found on planetsourcecode. However, in the end, the thumbnail quality winds up looking really crappy.
I looked into the PHP manual and saw that the second to last function I am using, imagecopyresized takes an optional paramater to set the image quality. I have messed with this value (even setting it to 100), and it still comes out really bad. The original jpeg quality is around 60 - 75, and the large versions look just fine. The function I am using to create the images after uploading is this:
function makeThumb($origFileName)
{
global $objAdmin;
$objSrcImg = imagecreatefromjpeg($origFileName);
/* grabs the height and width */
$newW = imagesx($objSrcImg);
$newH = imagesy($objSrcImg);
/* sets new size */
$newW = 100;
$newH = 150;
/* creates new image of that size */
$objDstImg = imagecreate($newW,$newH);
/* copies resized portion of original image into new image */
imagecopyresized($objDstImg,$objSrcImg,0,0,0,0,$newW,$newH,imagesx($objSrcImg),imagesy($objSrcImg));
/* return jpeg data back to browser */
imagejpeg($objDstImg, $objAdmin->thumbPath.basename($origFileName), 100);
}
As I mentioned, I didn't write this particular piece of code. Everything is the same (aside from me renaming the variables) and $objAdmin which is a class I use to store my global variables.
Any thoughts?