creating thumbnails
Posted: Wed Mar 30, 2005 6:38 pm
Im using the following code to create a thumbnail of an image stored in a database. the code works fine, however the quality of the thumbnail isnt so great. does anyone know of any changes i could make to the code to improve the quality?
feyd | Please review how to post code using
Code: Select all
$imageType = //function to get image type from database
$data = //function to get image data from database
header("Content-type: $imageType");
// get originalsize of image
$im = imagecreatefromstring($data);
$width = imagesx($im);
$height = imagesy($im);
// Set thumbnail-width to 100 pixel
$imgw = 100;
// calculate thumbnail-height from given width to maintain aspect ratio
$imgh = $height / $width * $imgw;
// create new image using thumbnail-size
$thumb = imagecreatetruecolor($imgw,$imgh);
// copy original image to thumbnail
imagecopyresized($thumb,$im,0,0,0,0,$imgw,$imgh,imagesx($im),imagesy($im));
// show thumbnail on screen
$out = imagejpeg($thumb);
print($out);
// clean memory
imagedestroy ($im);
imagedestroy ($thumb);feyd | Please review how to post code using
Code: Select all
andCode: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]