From d908520b7ebde8e209a5db89a505f959ad6b76c4 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 23 Feb 2010 09:21:02 +0000 Subject: New imagecache generation system. --- htdocs/index.php | 2 +- utils/imagecache.php | 32 ++++++++++++++++++++++++++- utils/modules/discography.php | 17 ++++++++++++++- utils/modules/gallery.php | 51 +++++++++++++++++++++++++++---------------- 4 files changed, 80 insertions(+), 22 deletions(-) diff --git a/htdocs/index.php b/htdocs/index.php index d68609a..fd5c762 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -5,7 +5,7 @@ include_once("config.php"); if($mode == "imagecache") { include_once($UTIL_DIR. "/imagecache.php"); - getCachedImage($uri, $mw, $mh); + getCachedImage($uri, $mod, $cat); return; } diff --git a/utils/imagecache.php b/utils/imagecache.php index 8aaaba9..811ba0c 100644 --- a/utils/imagecache.php +++ b/utils/imagecache.php @@ -1,6 +1,18 @@ width = $w; + $this->height = $h; + } +}; function rescale($image, $maxwidth, $maxheight) { @@ -31,8 +43,26 @@ function errorImage($message) imagedestroy($im); } -function getCachedImage($filename, $maxwidth, $maxheight) +function getCachedImage($filename, $mod, $cat) { + global $modules; + loadModule($mod); + if(!$modules[$mod]) die(404); + + $size = $modules[$mod]->getImageSize($cat); + $maxwidth = $size->width; + $maxheight = $size->height; + + /* + 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); diff --git a/utils/modules/discography.php b/utils/modules/discography.php index a8bfb5e..bc37022 100644 --- a/utils/modules/discography.php +++ b/utils/modules/discography.php @@ -139,7 +139,7 @@ class Disc { $str .= "
\n"; $str .= " cover."\">\n"; $str .= " \"".$this-title." cover\"\n"; - $str .= " src=\"?mode=imagecache&uri=" . $this->cover . "&mw=200&mh=200\"/>\n"; + $str .= " src=\"?mode=imagecache&uri=" . $this->cover . "&mod=discography&cat=cover\"/>\n"; $str .= " \n"; $str .= "
\n"; $str .= " "; @@ -247,6 +247,15 @@ class Discography { $key = $disc->releasetime; $this->discs[$key] = $disc; } + + public function getImageSize($cat) + { + switch($cat) { + default: + case "cover": + return new ImageSize($this->coverwidth, $this->coverheight); + } + } public function write() { @@ -267,6 +276,12 @@ class Discography { $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->file); + + $discography = $dom->documentElement; + + $this->coverwidth = $discography->getAttribute('coverwidth'); + $this->coverheight = $discography->getAttribute('coverheight'); + $discs = $dom->getElementsByTagName('disc'); foreach($discs as $d) { diff --git a/utils/modules/gallery.php b/utils/modules/gallery.php index e9b2934..d2b751c 100644 --- a/utils/modules/gallery.php +++ b/utils/modules/gallery.php @@ -42,18 +42,18 @@ class Photo { htmlspecialchars($this->image, ENT_QUOTES, "UTF-8") . "\"/>\n"); } - public function show($indent, $maxwidth = 100, $maxheight = 100, $showbig = false) + public function show($indent, $cat) { $str = ""; $str .= $indent."\n"; - if($showbig) $str .= $indent." path . "/" . $this->image . "\">\n"; + if($cat == "photo") $str .= $indent." path . "/" . $this->image . "\">\n"; $str .= $indent." \n"; $str .= $indent." \"".$this-title."\"\n"; $str .= $indent." src=\"?mode=imagecache&uri=" - . $this->path . "/" . $this->image . "&mw=".$maxwidth."&mh=".$maxheight."\"/>\n"; + . $this->path . "/" . $this->image . "&mod=gallery&cat=".$cat."\"/>\n"; $str .= $indent." \n"; - if($showbig) $str .= $indent." \n"; + if($cat == "photo") $str .= $indent." \n"; $str .= $indent." " . $this->title . "\n"; $str .= $indent."\n"; return $str; @@ -100,7 +100,7 @@ class Album { fwrite($fp, " \n"); } - public function show($indent, $maxwidth, $maxheight) + public function show($indent) { global $page; @@ -109,7 +109,7 @@ class Album { $str .= $indent." " . $this->title . "\n"; foreach($this->photos as $photo) { $str .= $indent." id."&p=".$photo->id."\">\n"; - $str .= $photo->show($indent." ", $maxwidth, $maxheight); + $str .= $photo->show($indent." ", "albumicon"); $str .= $indent." \n"; } $str .= $indent."\n"; @@ -117,7 +117,7 @@ class Album { return $str; } - public function showIcon($indent, $maxwidth, $maxheight) + public function showIcon($indent) { global $page; @@ -126,14 +126,14 @@ class Album { $str .= $indent."id."\">\n"; $str .= $indent." ".$this->title."\n"; $str .= $indent." \n"; - $str .= $this->photos[$this->icon]->show($indent." ", $maxwidth, $maxheight); + $str .= $this->photos[$this->icon]->show($indent." ", "albumicon"); $str .= $indent." \n"; $str .= $indent."\n"; return $str; } - public function showPhoto($indent, $photo, $maxwidth, $maxheight, $maxwidth_icon, $maxheight_icon) + public function showPhoto($indent, $photo) { global $GLOBALS; @@ -141,12 +141,12 @@ class Album { $str = ""; - $str = $this->photos[$photo]->show($indent, $maxwidth, $maxheight, true); + $str = $this->photos[$photo]->show($indent, "photo"); $str .= $indent."\n"; if($this->photos[$photo - 1]) { $str .= $indent." \n"; - $str .= $this->photos[$photo - 1]->show($indent." ", $maxwidth_icon, $maxheight_icon); + $str .= $this->photos[$photo - 1]->show($indent." ", "navicon"); $str .= $indent." \n"; } else { $str .= $indent." \n"; @@ -160,7 +160,7 @@ class Album { if($this->photos[$photo + 1]) { $str .= $indent." \n"; - $str .= $this->photos[$photo + 1]->show($indent." ", $maxwidth_icon, $maxheight_icon); + $str .= $this->photos[$photo + 1]->show($indent." ", "navicon"); $str .= $indent." \n"; } else { $str .= $indent." \n"; @@ -269,7 +269,7 @@ class Gallery { unpackImages($_FILES['images'], $album); $this->add($album); $this->write(); - echo $album->show("", $this->maxwidth_icon, $this->maxheight_icon); + echo $album->show("", "albumicon"); break; case "select": @@ -339,7 +339,7 @@ class Gallery { $photo = array_rand($this->albums[$album]->photos); $str .= " \n"; - $str .= $this->albums[$album]->photos[$photo]->show(" ", $this->maxwidth_rand, $this->maxheight_rand); + $str .= $this->albums[$album]->photos[$photo]->show(" ", "randomimage"); $str .= " \n"; return $str; @@ -351,7 +351,7 @@ class Gallery { $str .= "\n\n"; foreach($this->albums as $album) { - $str .= $album->showIcon(" ", $this->maxwidth_icon, $this->maxheight_icon); + $str .= $album->showIcon(" "); } $str .= "\n"; @@ -363,9 +363,7 @@ class Gallery { $str = ""; if($this->albums[$album]) { - $str .= $this->albums[$album]->showPhoto(" ", $photo, - $this->maxwidth, $this->maxheight, - $this->maxwidth_icon, $this->maxheight_icon); + $str .= $this->albums[$album]->showPhoto(" ", $photo); } return $str; @@ -387,7 +385,7 @@ class Gallery { default: if($p != "" && $a != "") $str .= $this->showPhoto($a, $p); else if($a != "" && $this->albums[$a] && $p == "") - $str .= $this->albums[$a]->show(" ", $this->maxwidth_icon, $this->maxheight_icon); + $str .= $this->albums[$a]->show(" "); else $str .= $this->showAlbums(); break; } @@ -410,6 +408,21 @@ class Gallery { return $maxid + 1; } + public function getImageSize($cat) + { + switch($cat) { + case "photo": + return new ImageSize($this->maxwidth, $this->maxheight); + case "randomimage": + return new ImageSize($this->maxwidth_rand, $this->maxheight_rand); + case "navicon": + return new ImageSize($this->maxwidth_icon * 0.7, $this->maxheight_icon * 0.7); + default: + case "albumicon": + return new ImageSize($this->maxwidth_icon, $this->maxheight_icon); + } + } + public function write() { $fp = fopen($this->file, "w"); -- cgit v1.2.3