[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ©Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_handlers/resize_handler.php,v $ 14 | $Revision: 1.5 $ 15 | $Date: 2005/12/14 17:37:34 $ 16 | $Author: sweetas $ 17 +----------------------------------------------------------------------------+ 18 */ 19 if (!defined('e107_INIT')) { exit; } 20 21 /* 07-04-2004 - unknown: removed source/destination file rewriting, this should not break existing code */ 22 /* 09-04-2004 - unknown: source/destination file should be quoted, otherwise files with spaces can't be handled */ 23 function resize_image($source_file, $destination_file, $type = "upload", $model = "") { 24 25 global $pref; 26 27 $new_height = 0; 28 $mode = ($pref['resize_method'] ? $pref['resize_method'] : "gd2"); 29 if ($type == "upload") { 30 $new_size = ($pref['im_width'] ? $pref['im_width'] : 400); 31 } 32 else if(is_numeric($type)) { 33 $new_size = $type; 34 } else { 35 $new_size = ($pref['im_width'] ? $pref['im_width'] : 120); 36 //avatar 37 $new_height = ($pref['im_height'] ? $pref['im_height'] : 100); 38 //avatar 39 } 40 41 $im_quality = ($pref['im_quality'] ? $pref['im_quality'] : 99); 42 43 $image_stats = getimagesize($source_file); 44 45 if ($image_stats[0] <= $type && is_numeric($type)) { 46 return false; 47 } 48 49 if ($image_stats == null) { 50 echo "<b>DEBUG</b> image_stats are null<br />"; 51 return false; 52 } 53 54 if ($image_stats[2] != 1 && $image_stats[2] != 2 && $image_stats[2] != 3 && ($mode == 'gd1' || $mode == 'gd2')) { 55 echo "<b>DEBUG</b> Wrong image type<br />"; 56 return FALSE; 57 } 58 $imagewidth = $image_stats[0]; 59 $imageheight = $image_stats[1]; 60 if ($imagewidth <= $new_size && ($imageheight <= $new_height || $new_height == 0)) { 61 return TRUE; 62 } 63 $ratio = ($imagewidth / $new_size); 64 $new_imageheight = round($imageheight / $ratio); 65 if (($new_height <= $new_imageheight) && $new_height > 0) { 66 $ratio = $new_imageheight / $new_height; 67 $new_imageheight = $new_height; 68 $new_size = round($new_size / $ratio); 69 70 } 71 if ($mode == "ImageMagick") { 72 if ($destination_file == "stdout") { 73 /* if destination is stdout, output directly to the browser */ 74 $destination_file = "jpg:-"; 75 header("Content-type: image/jpeg"); 76 passthru ($pref['im_path']."convert -quality ".$im_quality." -antialias -geometry ".$new_size."x".$new_imageheight." ".escapeshellarg($source_file)." '".$destination_file."'"); 77 } else { 78 /* otherwise output to file */ 79 if ($model == "copy") { 80 $name = substr($destination_file, (strrpos($destination_file, "/")+1)); 81 $name2 = "thumb_".$name; 82 $destination_file = str_replace($name, $name2, $destination_file); 83 } 84 exec ($pref['im_path']."convert -quality ".$im_quality." -antialias -geometry ".$new_size."x".$new_imageheight." ".escapeshellarg($source_file)." '".$destination_file."'"); 85 86 } 87 } 88 else if($mode == "gd1") { 89 if ($image_stats[2] == 2) 90 $src_img = imagecreatefromjpeg($source_file); 91 else 92 $src_img = imagecreatefrompng($source_file); 93 if (!$src_img) { 94 return FALSE; 95 } 96 $dst_img = imagecreate($new_size, $new_imageheight); 97 imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_size, $new_imageheight, $imagewidth, $imageheight); 98 if ($model == "copy") { 99 $name = substr($destination_file, (strrpos($destination_file, "/")+1)); 100 $name2 = "thumb_".$name; 101 $destination_file = str_replace($name, $name2, $destination_file); 102 } 103 104 if ($destination_file == "stdout") { 105 header("Content-type: image/jpeg"); 106 imagejpeg($dst_img, '', $im_quality); 107 } else { 108 imagejpeg($dst_img, $destination_file, $im_quality); 109 imagedestroy($src_img); 110 imagedestroy($dst_img); 111 } 112 113 } 114 else if($mode == "gd2") { 115 116 if ($image_stats[2] == 2) 117 $src_img = imagecreatefromjpeg($source_file); 118 else 119 $src_img = imagecreatefrompng($source_file); 120 if (!$src_img) { 121 return FALSE; 122 } 123 124 $dst_img = imagecreatetruecolor($new_size, $new_imageheight); 125 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_size, $new_imageheight, $imagewidth, $imageheight); 126 127 if ($model == "copy") { 128 $name = substr($destination_file, (strrpos($destination_file, "/")+1)); 129 $name2 = "thumb_".$name; 130 $destination_file = str_replace($name, $name2, $destination_file); 131 } 132 if ($destination_file == "stdout") { 133 header("Content-type: image/jpeg"); 134 imagejpeg($dst_img, '', $im_quality); 135 } else { 136 imagejpeg($dst_img, $destination_file, $im_quality); 137 imagedestroy($src_img); 138 imagedestroy($dst_img); 139 } 140 } 141 142 @chmod($destination_file, 0644); 143 if ($pref['image_owner']) { 144 @chown($destination_file, $pref['image_owner']); 145 } 146 147 $image_stats = getimagesize($destination_file); 148 if ($image_stats == null) { 149 // @unlink($source_file); 150 return FALSE; 151 } else { 152 return TRUE; 153 } 154 } 155 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |