diff options
author | deva <deva> | 2011-11-01 09:32:21 +0000 |
---|---|---|
committer | deva <deva> | 2011-11-01 09:32:21 +0000 |
commit | 42c62cb041a2b2b95c9cda0c20fcf70334fd244c (patch) | |
tree | 38371eb37ff7348585ee84438b326c25055e2cbe /utils/imagecache.php | |
parent | 208e3b642149a9ac701a43397d31990f9b27ca79 (diff) |
Rewl og krat... needs cleaning up - after port to GIT.origin
Diffstat (limited to 'utils/imagecache.php')
-rw-r--r-- | utils/imagecache.php | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/utils/imagecache.php b/utils/imagecache.php index 3f91d79..5adf54c 100644 --- a/utils/imagecache.php +++ b/utils/imagecache.php @@ -7,16 +7,38 @@ include_once($UTIL_DIR . "/modules.php"); class ImageSize { public $width; public $height; + public $cut; - public function ImageSize($w, $h) + public function ImageSize($w, $h, $c) { $this->width = $w; $this->height = $h; + $this->cut = $c; } }; -function rescale($image, $width, $height) +function rescale_nocut($image, $maxwidth, $maxheight) { + $width = imagesx($image); + $height = imagesy($image); + + if($width <= $maxwidth && $height <= $maxheight) return $image; + + $scale = 1; + if($width > $maxwidth) $scale = $width / $maxwidth; + if($height / $scale > $maxheight) $scale = $height / $maxheight; + + $image_p = imagecreatetruecolor($width / $scale, $height / $scale); + imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width / $scale, + $height / $scale, $width, $height); + + return $image_p; +} + +function rescale($image, $width, $height, $cut) +{ + if($cut == false) return rescale_nocut($image, $width, $height); + $aspect = $width / $height; $w = imagesx($image); @@ -60,27 +82,19 @@ function errorImage($message) function getCachedImage($filename, $mod, $cat) { - global $modules; - loadModule($mod); - if(!$modules[$mod]) die(404); - if(!method_exists($modules[$mod], "getImageSize")) die(404); + $module = loadModule($mod); + if(!$module) die(404); + if(!method_exists($module, "getImageSize")) die(404); - $size = $modules[$mod]->getImageSize($cat); + $size = $module->getImageSize($cat); $maxwidth = $size->width; $maxheight = $size->height; + $cut = $size->cut; - /* - if($mod == "discography") { - if($cat == "cover") { $maxwidth = 100; $maxheight = 100; } - } - if($mod == "gallery") { - if($cat == "randomimage") { $maxwidth = 100; $maxheight = 100; } - if($cat == "photo") { $maxwidth = 100; $maxheight = 100; } - if($cat == "albumicon") { $maxwidth = 100; $maxheight = 100; } - } - */ global $IMAGECACHE, $JPEG_CACHE_QUALITY; - $fullfilename = $IMAGECACHE . "/" . $maxwidth . ":" . $maxheight . ":". urlencode($filename); + $cutstr = "uncut"; + if($cut) $cutstr = "cut"; + $fullfilename = $IMAGECACHE . "/" . $maxwidth . ":" . $maxheight . ":" . $cutstr . ":" . urlencode($filename); // Test the storage dir if(!file_exists($IMAGECACHE)) { @@ -106,21 +120,21 @@ function getCachedImage($filename, $mod, $cat) case ".jpg": $image = imagecreatefromjpeg(urldecode($filename)); if(!$image) errorImage("Could not read: ". $filename); - $image = rescale($image, $maxwidth, $maxheight); + $image = rescale($image, $maxwidth, $maxheight, $cut); imagejpeg($image, $fullfilename, $JPEG_CACHE_QUALITY); break; case ".gif": $image = imagecreatefromgif(urldecode($filename)); if(!$image) errorImage("Could not read: ". $filename); - $image = rescale($image, $maxwidth, $maxheight); + $image = rescale($image, $maxwidth, $maxheight, $cut); imagegif($image, $fullfilename); break; case ".png": $image = imagecreatefrompng(urldecode($filename)); if(!$image) errorImage("Could not read: ". $filename); - $image = rescale($image, $maxwidth, $maxheight); + $image = rescale($image, $maxwidth, $maxheight, $cut); imagepng($image, $fullfilename); break; |