This is a small script I use for thumbnail creation.
Step 1:
Put this code in a separate file, i.e. "thumbmaker.pnp":
<?
// Headers make the browser cache the image
Header ("Content-type: image/png");
Header ("Last-Modified: " . gmdate("D, d M Y H:i:s",mktime (0,0,0,1,1,2000)) . " GMT");
Header ("Expires: Mon, 26 Jul 2040 05:00:00 GMT");
Header ("Cache-Control: max-age=10000000, s-maxage=1000000, proxy-revalidate, must-revalidate");
// Open the original file that you want to make the thumb from
// the variable $originalfil is passed by a url querystring.
$seis = getImageSize($originalfil);
$original = imagecreatefromjpeg($originalfil);
// Specify height and width of your thumbnail
$h = 54;
$w = 72;
$xyrelation = $seis[0] / $seis[1];
$maalestokk = $seis[1] / $h;
$br = round($seis[0] / $maalestokk);
if ($br > $w) {
$br = $w;
$h = round($br / $xyrelation);
}
$thumb = imagecreatetruecolor($br, $h);
imagecopyresampled ( $thumb, $original, 0, 0, 0, 0, $br, $h, $seis[0], $seis[1]);
imagetruecolortopalette ( $thumb, false, 64); // reduces color depth so that the png output file is smaller. Note that the png thumbnails are MUCH smaller than jpegs of the same pixel size!
ImagePng($thumb);
imagedestroy($original);
imagedestroy($thumb);
?>
Step 2: In your image tag you put src="thumbmaker.php?originalfil=XXX".
Hope this works. Beware of typos, I have translated most of my variable names from Norwegian.
Helsing Torstein