diff options
author | deva <deva> | 2008-10-04 10:38:03 +0000 |
---|---|---|
committer | deva <deva> | 2008-10-04 10:38:03 +0000 |
commit | cce5e7710295021b41d9aaecc503a60fb99256be (patch) | |
tree | 660235be91fb821e976c7ae62347eb368ce87524 /utils/thumbnail.php |
Initial revision
Diffstat (limited to 'utils/thumbnail.php')
-rw-r--r-- | utils/thumbnail.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/utils/thumbnail.php b/utils/thumbnail.php new file mode 100644 index 0000000..f1f4b38 --- /dev/null +++ b/utils/thumbnail.php @@ -0,0 +1,39 @@ +<?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; +} +?>
\ No newline at end of file |