Sunday April 27 2003 at 16:51 GMT
For a while I've been meaning to get some auto-image-resizing code written for my gallery, so that I could just dump full-scale camera images into a directory and the resizing and decrease in quality (from original photo) would be taken care without me doing any more work. I got the code written with not too many problems, so it is auto-thumbnailing for the latest gallery. The problem I've found is that a) the quality is rubbish; b) the files are double the size compared to doing this in LView. Compare:
| Lview original | 20% quality | 50% quality | 80% quality |
| 1975bytes | 1483bytes | 2164bytes | 3323bytes |
Here's my PHP code:
if ($galleryName == "latest") {
$thumbnailLocation = $baseFileLocation . $galleryYear . "/" . $galleryName . "/thumbnail/" . $imageName; //echo($thumbnailLocation);
if (!file_exists($thumbnailLocation)) {
$largefileLocation = str_replace('thumbnail', 'large', $thumbnailLocation);
$originalimagesize = getimagesize($largefileLocation);
$originalimagewidth = $originalimagesize[0]; //echo($originalimagewidth);
$originalimageheight = $originalimagesize[1]; //echo($originalimageheight);
if (($originalimagewidth > $thumbnailWidth) || ($originalimageheight > $thumbnailHeight)) {
$mltwidth = $thumbnailWidth / $originalimagewidth; //echo("mltw" . $mltwidth);
$mltheight = $thumbnailHeight / $originalimageheight; //echo("mlth" . $mltheight);
$mlt = $mltwidth < $mltheight ? $mltwidth:$mltheight; //echo("mlt" . $mlt);
$newimagewidth = round($originalimagewidth * $mlt); //echo($newimagewidth);
$newimageheight = round($originalimageheight * $mlt); //echo($newimageheight);
$resizedimage = imagecreate($newimagewidth, $newimageheight);
imagecopyresized($resizedimage, imagecreatefromjpeg($largefileLocation), 0, 0, 0, 0, $newimagewidth, $newimageheight, $originalimagewidth, $originalimageheight);
imagejpeg($resizedimage, $thumbnailLocation);
}
At the moment, I'm leaving the quality at 100%. If anyone has any bright ideas on how I can increase the quality to be at least as good as the LView original whilst keeping the size about the same as the LView original, I'd be most happy to hear them.
Comments
Powered by
thinkthin