Hello,
I am using imagecopyresampled to create thumbnails from an image; however, the quality I am getting is very poor. Can anyone help me fix this?
Thanks,
SL
$twidth = "125"; // Maximum Width For Thumbnail Images
$theight = "100"; // Maximum Height For Thumbnail Images
$simg = imagecreatefromjpeg("$idir".$url); // Make A New Temporary Image To Create The Thumbanil From
$currwidth = imagesx($simg); // Current Image Width
$currheight = imagesy($simg); // Current Image Height
if ($currheight > $currwidth) { // If Height Is Greater Than Width
$zoom = $mwidth / $currheight; // Length Ratio For Width
$newheight = $mheight; // Height Is Equal To Max Height
$newwidth = $currwidth $zoom; // Creates The New Width
}
else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
$zoom = $mwidth / $currwidth; // Length Ratio For Height
$newwidth = $mwidth; // Width Is Equal To Max Width
$newheight = $currheight $zoom; // Creates The New Height
}
$dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail
imagetruecolortopalette($simg, false, 256); // Create New Color Pallete
$palsize = ImageColorsTotal($simg);
for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image
$colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use
}
imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It)
imagejpeg($dimg, "$mdir".$url); // Saving The Image
imagedestroy($simg); // Destroying The Temporary Image
imagedestroy($dimg); // Destroying The Other Temporary Image
Here are links to the created images from this script
original
http://www.desirethis.com/images/news/8.jpg
medium
http://www.desirethis.com/images/news/meds/8.jpg
thumbnail
http://www.desirethis.com/images/news/thumbs/8.jpg