[Linpha-cvs] SF.net SVN: linpha: [4634] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2006-11-10 15:46:34
|
Revision: 4634 http://svn.sourceforge.net/linpha/?rev=4634&view=rev Author: fangehrn Date: 2006-11-10 07:46:14 -0800 (Fri, 10 Nov 2006) Log Message: ----------- 2006-11-10 flo * implemented thumbnail folder with gdlib but the quality is quite bad...why? Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/lib/classes/image/gdlib/image.php trunk/linpha2/lib/classes/image/gdlib/thumbnail.php trunk/linpha2/lib/classes/image/gdlib/thumbnail_folder.php trunk/linpha2/lib/classes/image/imagemagick/thumbnail_folder.php trunk/linpha2/lib/classes/linpha.functions.php trunk/linpha2/lib/classes/linpha.image.class.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-11-10 13:42:45 UTC (rev 4633) +++ trunk/linpha2/ChangeLog 2006-11-10 15:46:14 UTC (rev 4634) @@ -1,3 +1,7 @@ +2006-11-10 flo + * implemented thumbnail folder with gdlib + but the quality is quite bad...why? + 2006-11-09 bzrudi * made sqlite work again (broken query) * fixed a couple of issues in view_meta Modified: trunk/linpha2/lib/classes/image/gdlib/image.php =================================================================== --- trunk/linpha2/lib/classes/image/gdlib/image.php 2006-11-10 13:42:45 UTC (rev 4633) +++ trunk/linpha2/lib/classes/image/gdlib/image.php 2006-11-10 15:46:14 UTC (rev 4634) @@ -56,7 +56,7 @@ /** * rotate image */ - LinImage::imageRotateGd($scaled_image,$this->rotate); + LinImage::GDimageRotate($scaled_image,$this->rotate); /** * save image Modified: trunk/linpha2/lib/classes/image/gdlib/thumbnail.php =================================================================== --- trunk/linpha2/lib/classes/image/gdlib/thumbnail.php 2006-11-10 13:42:45 UTC (rev 4633) +++ trunk/linpha2/lib/classes/image/gdlib/thumbnail.php 2006-11-10 15:46:14 UTC (rev 4634) @@ -57,13 +57,7 @@ /** * create image resources */ - switch($this->img_type) - { - case 1: $src_image = imagecreatefromgif($this->src_file); break; - case 2: $src_image = imagecreatefromjpeg($this->src_file); break; - case 3: $src_image = imagecreatefrompng($this->src_file); break; - default: return false;; - } + $src_image = LinImage::GDimagecreate($this->src_file,$this->img_type); $scaled_image = imagecreatetruecolor($this->img_thumbsize, $this->img_thumbsize); @@ -86,7 +80,7 @@ /** * rotate image */ - LinImage::imageRotateGd($scaled_image,$this->rotate); + LinImage::GDimageRotate($scaled_image,$this->rotate); /** * save image Modified: trunk/linpha2/lib/classes/image/gdlib/thumbnail_folder.php =================================================================== --- trunk/linpha2/lib/classes/image/gdlib/thumbnail_folder.php 2006-11-10 13:42:45 UTC (rev 4633) +++ trunk/linpha2/lib/classes/image/gdlib/thumbnail_folder.php 2006-11-10 15:46:14 UTC (rev 4634) @@ -29,6 +29,64 @@ if(!defined('LINPHA_DIR')) { exit(1); } -copy( LinImage::getCachePath('thumb',$array_ids[0]), $this->output_file ); +if( ! $im = @ImageCreateFromGIF (LINPHA_DIR.'/lib/graphics/thumb_folder.gif')) +{ + copy( $array_ids[0], $this->output_file ); + linLog(LOG_TYPE_IMPORT,LOG_ERR,'thumbnail',"Cannot create folder thumbnail"); +} +else +{ + for($i=1; list($key,$value) = each($array_thumbs); $i++ ) + { +// echo $value['file'].' '.$value['type'].'<br />'; + $im2 = LinImage::GDimagecreate($value['file'],$value['type']); + $src_width = ImageSX($im2); + $src_height = ImageSY($im2); + + switch($i) + { + case 1: + imagecopyresized( + $im,$im2, + 15,15, // int dstX, int dstY + 0,0, // int srcX, int srcY + 80,80, // int dstW, int dstH + $src_width,$src_height // int srcW, int srcH + ); + break; + case 2: + imagecopyresized( + $im,$im2, + 105,15, // int dstX, int dstY + 0,0, // int srcX, int srcY + 80,80, // int dstW, int dstH + $src_width,$src_height // int srcW, int srcH + ); + break; + case 3: + imagecopyresized( + $im,$im2, + 15,105, // int dstX, int dstY + 0,0, // int srcX, int srcY + 80,80, // int dstW, int dstH + $src_width,$src_height // int srcW, int srcH + ); + break; + case 4: + imagecopyresized( + $im,$im2, + 105,105, // int dstX, int dstY + 0,0, // int srcX, int srcY + 80,80, // int dstW, int dstH + $src_width,$src_height // int srcW, int srcH + ); + break; + } + + imagedestroy($im2); + } + + imagegif($im,$this->output_file); +} ?> \ No newline at end of file Modified: trunk/linpha2/lib/classes/image/imagemagick/thumbnail_folder.php =================================================================== --- trunk/linpha2/lib/classes/image/imagemagick/thumbnail_folder.php 2006-11-10 13:42:45 UTC (rev 4633) +++ trunk/linpha2/lib/classes/image/imagemagick/thumbnail_folder.php 2006-11-10 15:46:14 UTC (rev 4634) @@ -73,36 +73,37 @@ /** * create new unique tmp folder */ - for($i=0; file_exists(LinSql::getPath('tmp').'/thumb_folder_'.session_id().'_'.$i); $i++) { } - $tmp_folder = LinSql::getPath('tmp').'/thumb_folder_'.session_id().'_'.$i; - mkdir($tmp_folder,0700); + $tmp_folder = LinFilesys::createTmpFolder('thumb_folder'); /** - * run imagemagick + * create smaller thumbs and set up the convert string at the same time for later use */ - for($i=1; list($key,$value) = each($array_ids) ; $i++) - { - LinFilesys::linExec( $this->imagemagick_path."convert ". $value . " -quality 70 -resize 80x80 ".$tmp_folder . "/" . $i . "." . LinFilesys::getFileExtFromPath($value) ); - } $str = $this->imagemagick_path."convert ".LINPHA_DIR."/lib/graphics/thumb_folder.gif "; - - reset($array_ids); - for($i=1; list($key,$value) = each($array_ids); $i++ ) + reset($array_thumbs); + for($i=1; list($key,$value) = each($array_thumbs); $i++ ) { + switch($value['type']) // thumbnails are either jpg (files) or gifs (folders) + { + case '1': $fileext = 'gif'; break; + case '2': $fileext = 'jpg'; break; + default: $fileext = 'jpg'; break; + } + LinFilesys::linExec( $this->imagemagick_path."convert ". $value['file'] . " -quality 70 -resize 80x80 " . $tmp_folder . "/" . $i . "." . $fileext ); + switch($i) { case 1: - $str .= $tmp_folder."/1.".LinFilesys::getFileExtFromPath($value)." -geometry +15+15 -composite "; + $str .= $tmp_folder."/1.".$fileext." -geometry +15+15 -composite "; break; case 2: - $str .= $tmp_folder."/2.".LinFilesys::getFileExtFromPath($value)." -geometry +105+15 -composite "; + $str .= $tmp_folder."/2.".$fileext." -geometry +105+15 -composite "; break; case 3: - $str .= $tmp_folder."/3.".LinFilesys::getFileExtFromPath($value)." -geometry +15+105 -composite "; + $str .= $tmp_folder."/3.".$fileext." -geometry +15+105 -composite "; break; case 4: - $str .= $tmp_folder."/4.".LinFilesys::getFileExtFromPath($value)." -geometry +105+105 -composite "; + $str .= $tmp_folder."/4.".$fileext." -geometry +105+105 -composite "; break; } } @@ -123,10 +124,16 @@ /** * delete tmp folder */ - reset($array_ids); - for($i=1; list($key,$value) = each($array_ids) ; $i++) + reset($array_thumbs); + for($i=1; list($key,$value) = each($array_thumbs) ; $i++) { - unlink( $tmp_folder .'/'. $i . '.' . LinFilesys::getFileExtFromPath($value) ); + switch($value['type']) // thumbnails are either jpg (files) or gifs (folders) + { + case '1': $fileext = 'gif'; break; + case '2': $fileext = 'jpg'; break; + default: $fileext = 'jpg'; break; + } + unlink( $tmp_folder .'/'. $i . '.' . $fileext ); } rmdir($tmp_folder); Modified: trunk/linpha2/lib/classes/linpha.functions.php =================================================================== --- trunk/linpha2/lib/classes/linpha.functions.php 2006-11-10 13:42:45 UTC (rev 4633) +++ trunk/linpha2/lib/classes/linpha.functions.php 2006-11-10 15:46:14 UTC (rev 4634) @@ -527,6 +527,7 @@ * Action: * login, logout, rotate * fm_others, fm_upload, fm_delete, fm_move, fm_copy, fm_rename, fm_create_folder, fm_perm + * thumbnail, image * * * @param string $type log types Modified: trunk/linpha2/lib/classes/linpha.image.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.image.class.php 2006-11-10 13:42:45 UTC (rev 4633) +++ trunk/linpha2/lib/classes/linpha.image.class.php 2006-11-10 15:46:14 UTC (rev 4634) @@ -364,7 +364,7 @@ * and create array_ids which holds 4 image ids */ $query = $GLOBALS['linpha']->db->Execute("SELECT id, img_type FROM ".PREFIX."photos WHERE parent_id = '".LinSql::linAddslashes( $this->photo_id )."'"); - $array_ids = Array(); + $array_thumbs = Array(); $i=0; while($data = $query->FetchRow(ADODB_FETCH_NUM)) { @@ -373,15 +373,17 @@ break; } - if($data['1']==0) { // folders are gif files, all others are jpg + if($data['1']=='0') { // folders are gif files, all others are jpg $file = LinImage::getCachePath('thumb',$data['0'],'gif'); + $type = '1'; } else { $file = LinImage::getCachePath('thumb',$data['0'],'jpg'); + $type = '2'; } if( file_exists( $file ) ) { - $array_ids[] = $file; + $array_thumbs[] = array('id' => $data['0'],'file' => $file, 'type' => $type); $i++; } } @@ -389,7 +391,7 @@ /** * no images found in this folder */ - if(count($array_ids) == 0) + if(count($array_thumbs) == 0) { return false; } @@ -631,11 +633,11 @@ * @param int $angle angle to rotate * @author flo */ -function imageRotateGd(& $src_img, $angle) +function GDimageRotate(& $src_img, $angle) { - if(function_exists('imagerotate')) + if($angle != "0") { - if($angle != "0") + if(function_exists('imagerotate')) { /** * flip $angle, because with this function, left means right, and right means left :-) @@ -644,12 +646,25 @@ $angle = $angle % 360; $src_img = imagerotate($src_img,$angle,0); } + else + { + linLog(LOG_TYPE_META,LOG_WARNING,'rotate',"Cannot rotate image becuase the function imagerotate() doesnt exists, consider upgrading your php version"); + } } - else +} + +function GDimagecreate($src_file,$img_type) +{ + switch($img_type) { - linLog(LOG_TYPE_META,LOG_WARNING,'rotate',"Cannot rotate image becuase the function imagerotate() doesnt exists, consider upgrading your php version"); + case 1: $src_image = imagecreatefromgif($src_file); break; + case 2: $src_image = imagecreatefromjpeg($src_file); break; + case 3: $src_image = imagecreatefrompng($src_file); break; + default: return false; } + + return $src_image; } - + } // end class linImage ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |