I am using ImageCopyResized() to resize images uploaded by users so all images are the same size. I have everything working just fine, however, the quality of the resized image is really poor. The resized images are really jagged.
You can see my script at:
http://joel.savvynet.com/~joel/resize.php?size=640&string=hello
go ahead and change the size value to see the results, (1024 is the original size)
I know how to change the jpeg compression settings on the image, but that doesn't seem to help this problem.
Does anyone have any suggestions on how to improve quality? Thanks.
Here is my source code for that script.
<?
Header("Content-type: image/jpeg");
// $size and $string are passed from the URL
$font = "/home/joel/public_html/ARIALBD.TTF"; // load the font
$im = imagecreatefromjpeg("MVC-069X.JPG"); // create the source image from jpeg file
if(ImageSX($im) > ImageSY($im)) // image is wider than it is tall
{
$width = $size;
$height = $width (ImageSY($im) / ImageSX($im));
}
else // image is taller than it is wide, or both dimensions are the same
{
$height = $size;
$width = $height (ImageSX($im) / ImageSY($im));
}
$im2=ImageCreate($width, $height); // create the destination image, with the correct dimensions
$white = ImageColorAllocate ($im2, 255, 255, 255); // allocate a white color
$black = ImageColorAllocate ($im2, 0, 0, 0); // allocate a black color
imagecopyresized($im2, $im, 0,0,0,0, $width, $height, ImageSX($im), ImageSY($im)); // do the resizing
$text_size = ImageTTFBBox(12, 0, $font, $string);
ImageTTFText ($im2, 12, 0, $width - 6 - $text_size[4], $height - 6 - $text_size[1], $white, $font,
$string);
Imagejpeg($im2,'', 75); // display the new, resized image
ImageDestroy($im);
ImageDestroy($im2);
?>