<?php function thumbnail($album, $file, $maxwidth, $maxheight) { global $ALBUMS_DIR; if($file =="") return "No such image"; // Config $quality = 70; $width = $maxwidth; $height = $maxheight; // Filenames $thumbnaildir = $ALBUMS_DIR . "/" . $album . "/thumbnails/"; $thumbnail = $thumbnaildir . $maxwidth . "x" . $maxheight . "_" . $file; $original = $ALBUMS_DIR . "/" . $album . "/" . $file; if(!file_exists($thumbnaildir)) { // The thumbnaildir doesn't exist, create it. mkdir($thumbnaildir, 0755); } // Create thumbnail if(!file_exists($thumbnail)) { list($width_orig, $height_orig) = getimagesize($original); if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($original); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p, $thumbnail, $quality); } // Return thumbnail filename return $thumbnail; } ?>