X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=8260cc967ddc21234094f6e76588acb31d272013;hp=a9e3e686ea3e52fa682d6792de91ba8cdfaf9c12;hb=38b33998a89dc05f4fc7c90ba6eabb29301f131a;hpb=1532cb592eb45670d0d72fe5e9acb1f5b0fb31c9 diff --git a/phpfspot.class.php b/phpfspot.class.php index a9e3e68..8260cc9 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -66,7 +66,7 @@ class PHPFSPOT { ); /* Check necessary requirements */ - if(!$this->checkRequirements()) { + if(!$this->check_requirements()) { exit(1); } @@ -129,12 +129,7 @@ class PHPFSPOT { /* Check if some tables need to be created */ $this->check_config_table(); - /* include Smarty template engine */ - if(!$this->check_readable($this->cfg->smarty_path .'/libs/Smarty.class.php')) { - exit(1); - } - require $this->cfg->smarty_path .'/libs/Smarty.class.php'; - /* overload Smarty class if our own template handler */ + /* overload Smarty class with our own template handler */ require_once "phpfspot_tmpl.php"; $this->tmpl = new PHPFSPOT_TMPL($this); @@ -591,6 +586,10 @@ class PHPFSPOT { $max_size = 125; // max font size in % $min_size = 75; // min font size in % + // color + $max_sat = hexdec('cc'); + $min_sat = hexdec('44'); + // get the largest and smallest array values $max_qty = max(array_values($tags)); $min_qty = min(array_values($tags)); @@ -604,6 +603,7 @@ class PHPFSPOT { // determine the font-size increment // this is the increase per tag quantity (times used) $step = ($max_size - $min_size)/($spread); + $step_sat = ($max_sat - $min_sat)/($spread); // loop through our tag array foreach ($tags as $key => $value) { @@ -619,8 +619,14 @@ class PHPFSPOT { // uncomment if you want sizes in whole %: $size = ceil($size); + $color = $min_sat + ($value - $min_qty) * $step_sat; + + $r = '44'; + $g = dechex($color); + $b = '88'; + if(isset($this->tags[$key])) { - $output.= "". $this->tags[$key] .", "; + $output.= "". $this->tags[$key] .", "; } } @@ -1292,110 +1298,134 @@ class PHPFSPOT { } $src_img = @imagecreatefromjpeg($orig_image); + $handler = "gd"; break; case 'image/png': $src_img = @imagecreatefrompng($orig_image); + $handler = "gd"; break; - } + case 'image/tiff': + + $src_img = new Imagick($orig_image); + print_r($src_img->queryFormats()); + + $handler = "imagick"; + exit(1); + break; - if(!$src_img) { - print "Can't load image from ". $orig_image ."\n"; - return false; } - /* grabs the height and width */ - $cur_width = imagesx($src_img); - $cur_height = imagesy($src_img); - // If requested width is more then the actual image width, - // do not generate a thumbnail, instead safe the original - // as thumbnail but with lower quality. But if the image - // is to heigh too, then we still have to resize it. - if($width >= $cur_width && $cur_height < $this->cfg->thumb_height) { - $result = imagejpeg($src_img, $thumb_image, 75); - imagedestroy($src_img); - return true; - } + switch($handler) { - // If the image will be rotate because EXIF orientation said so - // 'virtually rotate' the image for further calculations - if($rotate == 90 || $rotate == 270) { - $tmp = $cur_width; - $cur_width = $cur_height; - $cur_height = $tmp; - } + case 'gd': - /* calculates aspect ratio */ - $aspect_ratio = $cur_height / $cur_width; + if(!isset($src_img) || empty($src_img)) { + print "Can't load image from ". $orig_image ."\n"; + return false; + } - /* sets new size */ - if($aspect_ratio < 1) { - $new_w = $width; - $new_h = abs($new_w * $aspect_ratio); - } else { - /* 'virtually' rotate the image and calculate it's ratio */ - $tmp_w = $cur_height; - $tmp_h = $cur_width; - /* now get the ratio from the 'rotated' image */ - $tmp_ratio = $tmp_h/$tmp_w; - /* now calculate the new dimensions */ - $tmp_w = $width; - $tmp_h = abs($tmp_w * $tmp_ratio); - - // now that we know, how high they photo should be, if it - // gets rotated, use this high to scale the image - $new_h = $tmp_h; - $new_w = abs($new_h / $aspect_ratio); - - // If the image will be rotate because EXIF orientation said so - // now 'virtually rotate' back the image for the image manipulation - if($rotate == 90 || $rotate == 270) { - $tmp = $new_w; - $new_w = $new_h; - $new_h = $tmp; - } - } + /* grabs the height and width */ + $cur_width = imagesx($src_img); + $cur_height = imagesy($src_img); + + // If requested width is more then the actual image width, + // do not generate a thumbnail, instead safe the original + // as thumbnail but with lower quality. But if the image + // is to heigh too, then we still have to resize it. + if($width >= $cur_width && $cur_height < $this->cfg->thumb_height) { + $result = imagejpeg($src_img, $thumb_image, 75); + imagedestroy($src_img); + return true; + } - /* creates new image of that size */ - $dst_img = imagecreatetruecolor($new_w, $new_h); + // If the image will be rotate because EXIF orientation said so + // 'virtually rotate' the image for further calculations + if($rotate == 90 || $rotate == 270) { + $tmp = $cur_width; + $cur_width = $cur_height; + $cur_height = $tmp; + } - imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255)); + /* calculates aspect ratio */ + $aspect_ratio = $cur_height / $cur_width; - /* copies resized portion of original image into new image */ - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img)); + /* sets new size */ + if($aspect_ratio < 1) { + $new_w = $width; + $new_h = abs($new_w * $aspect_ratio); + } else { + /* 'virtually' rotate the image and calculate it's ratio */ + $tmp_w = $cur_height; + $tmp_h = $cur_width; + /* now get the ratio from the 'rotated' image */ + $tmp_ratio = $tmp_h/$tmp_w; + /* now calculate the new dimensions */ + $tmp_w = $width; + $tmp_h = abs($tmp_w * $tmp_ratio); + + // now that we know, how high they photo should be, if it + // gets rotated, use this high to scale the image + $new_h = $tmp_h; + $new_w = abs($new_h / $aspect_ratio); + + // If the image will be rotate because EXIF orientation said so + // now 'virtually rotate' back the image for the image manipulation + if($rotate == 90 || $rotate == 270) { + $tmp = $new_w; + $new_w = $new_h; + $new_h = $tmp; + } + } - /* needs the image to be flipped horizontal? */ - if($flip_hori) { - $this->_debug("(FLIP)"); - $dst_img = $this->flipImage($dst_img, 'hori'); - } - /* needs the image to be flipped vertical? */ - if($flip_vert) { - $this->_debug("(FLIP)"); - $dst_img = $this->flipImage($dst_img, 'vert'); - } + /* creates new image of that size */ + $dst_img = imagecreatetruecolor($new_w, $new_h); - if($rotate) { - $this->_debug("(ROTATE)"); - $dst_img = $this->rotateImage($dst_img, $rotate); - } + imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255)); - /* write down new generated file */ - $result = imagejpeg($dst_img, $thumb_image, 75); + /* copies resized portion of original image into new image */ + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img)); - /* free your mind */ - imagedestroy($dst_img); - imagedestroy($src_img); + /* needs the image to be flipped horizontal? */ + if($flip_hori) { + $this->_debug("(FLIP)"); + $dst_img = $this->flipImage($dst_img, 'hori'); + } + /* needs the image to be flipped vertical? */ + if($flip_vert) { + $this->_debug("(FLIP)"); + $dst_img = $this->flipImage($dst_img, 'vert'); + } - if($result === false) { - print "Can't write thumbnail ". $thumb_image ."\n"; - return false; - } + if($rotate) { + $this->_debug("(ROTATE)"); + $dst_img = $this->rotateImage($dst_img, $rotate); + } - return true; + /* write down new generated file */ + $result = imagejpeg($dst_img, $thumb_image, 75); + + /* free your mind */ + imagedestroy($dst_img); + imagedestroy($src_img); + + if($result === false) { + print "Can't write thumbnail ". $thumb_image ."\n"; + return false; + } + + return true; + + break; + + case 'imagick': + + break; + + } } // create_thumbnail() @@ -1794,7 +1824,7 @@ class PHPFSPOT { /** * check if all requirements are met */ - private function checkRequirements() + private function check_requirements() { if(!function_exists("imagecreatefromjpeg")) { print "PHP GD library extension is missing
\n"; @@ -1823,6 +1853,11 @@ class PHPFSPOT { print "PEAR Console_Getopt package is missing
\n"; $missing = true; } + @include_once $this->cfg->smarty_path .'/libs/Smarty.class.php'; + if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) { + print "Smarty template engine can not be found in ". $this->cfg->smarty_path ."/libs/Smarty.class.php
\n"; + $missing = true; + } ini_restore('track_errors'); if(isset($missing)) @@ -1830,7 +1865,7 @@ class PHPFSPOT { return true; - } // checkRequirements() + } // check_requirements() private function _debug($text) { @@ -1845,7 +1880,7 @@ class PHPFSPOT { */ public function checkifImageSupported($mime) { - if(in_array($mime, Array("image/jpeg", "image/png"))) + if(in_array($mime, Array("image/jpeg", "image/png", "image/tiff"))) return true; return false;