PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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?
$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);