Changeset 211
- Timestamp:
- 05/27/07 17:27:34 (1 year ago)
- Files:
-
- trunk/api/inc/imagetoolkit.gd.php (modified) (9 diffs)
- trunk/api/inc/imagetoolkit.imagemagick.php (modified) (3 diffs)
- trunk/api/inc/imagetoolkit.php (modified) (11 diffs)
- trunk/api/inc/system.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/api/inc/imagetoolkit.gd.php
r207 r211 8 8 class ImageToolkitGD extends ImageToolkit 9 9 { 10 11 /** 12 * @return boolean 13 */ 14 public static function isAvailable() { 15 return extension_loaded("gd"); 16 } 10 17 11 18 /** … … 14 21 * @return Handler 15 22 */ 16 function imageCreateFromType () {23 private function imageCreateFromType () { 17 24 18 25 switch ($this->imageType) { … … 39 46 40 47 /** 41 * Ecrit l'image redimensionnᅵe.48 * Write the new image 42 49 * @access private 43 50 */ 44 function imageWriteFromType ($image, $quality) {51 private function imageWriteFromType ($image, $quality) { 45 52 46 53 switch ($this->imageType){ … … 60 67 61 68 /** 62 * Remplit les champs principaux de la classe.69 * Fill in main fields of the class 63 70 * 64 71 * @access private 65 72 */ 66 function setSrcInfos () {73 protected function setSrcInfos () { 67 74 if ($this->image != "") { 68 75 // Lit les dimensions de l'image … … 79 86 * @access static 80 87 */ 81 function getImageDimensions($path) {82 if (is_file ($path)) {83 $size = GetImageSize ($path);84 return sprintf ('width="%s" height="%s"', $size[0], $size[1]);88 public function getImageDimensions($path) { 89 if (is_file($path)) { 90 $size = GetImageSize($path); 91 return sprintf('width="%s" height="%s"', $size[0], $size[1]); 85 92 } 86 93 return ''; … … 88 95 89 96 /** 90 * Crᅵe l'image redimentionnᅵe. Il faut prᅵalablement avoir apellᅵ la mᅵthode 91 * setDestSize(...) 92 * @param String $img_dest Chemin oᅵ il faut ᅵcrire l'image redimensionnᅵe. 93 */ 94 function createThumb ($img_dest) { 97 * Create the resized image. Need to call the function setDestSize() 98 * @param String $img_dest File path to store the resozed image 99 */ 100 function createThumb($img_dest) { 95 101 $this->imageDest = $img_dest; 96 102 97 // Cr ᅵer la vignette ?103 // Create the resized image ? 98 104 if ($this->canResize ()) { 99 105 100 // Copie dedans l'image initiale redimensionnᅵe101 $srcHandler = $this->ImageCreateFromType ($this->image, $this->imageType);106 // Loads image from source file 107 $srcHandler = $this->ImageCreateFromType($this->image, $this->imageType); 102 108 103 109 104 110 /* GD 2 */ 105 111 if ($this->gdVersion() == 2) { 106 107 // Crᅵe une image vierge aux bonnes dimensions108 112 $destHandler = ImageCreateTrueColor ($this->imageDestWidth, $this->imageDestHeight); 109 113 ImageCopyResampled ($destHandler, $srcHandler, 0, 0, $this->decalW, $this->decalH, $this->imageDestWidth, $this->imageDestHeight, $this->cropW, $this->cropH); … … 112 116 /* GD 1 */ 113 117 else { 114 115 // Crᅵe une image vierge aux bonnes dimensions116 118 $destHandler = ImageCreate ($this->imageDestWidth, $this->imageDestHeight); 117 119 imagecopyresized ($destHandler, $srcHandler, 0, 0, $this->decalW, $this->decalH, $this->imageDestWidth, $this->imageDestHeight, $this->cropW, $this->cropH); 118 120 } 119 121 120 // Sa uve la nouvelleimage122 // Save the new image 121 123 if (!$this->ImageWriteFromType ($destHandler, 95)) { 122 124 throw new Pluf_HTTP_ImageException(); 123 125 } 124 @chmod ($this->imageDest, 077 7);125 126 // D ᅵtruis les tampons126 @chmod ($this->imageDest, 0775); 127 128 // Destroy image handle 127 129 ImageDestroy ($destHandler); 128 130 ImageDestroy ($srcHandler); … … 132 134 133 135 /** 134 * Retourne la version exacte de GD136 * Get the exact GD installed version 135 137 * @return Version exacte de GD 136 138 */ 137 function gdVersionExact () {139 public static function gdVersionExact () { 138 140 static $gd_version_number = null; 139 141 if ($gd_version_number === null) { … … 162 164 * @return 1 ou 2 pour GD1 ou GD2 163 165 */ 164 function gdVersion ($user_ver = 0) {165 166 if (! extension_loaded('gd')) {166 public function gdVersion ($user_ver = 0) { 167 168 if (!extension_loaded('gd')) { 167 169 return; 168 170 } trunk/api/inc/imagetoolkit.imagemagick.php
r209 r211 6 6 class ImageToolkitImageMagick extends ImageToolkit { 7 7 var $forceResizeCmd = false; 8 9 /** 10 * @return boolean 11 */ 12 public static function isAvailable() { 13 if (!defined('IMAGE_TRANSFORM_IM_PATH')) { 14 $path = dirname(System::which('convert')) . DIRECTORY_SEPARATOR; 15 define('IMAGE_TRANSFORM_IM_PATH', $path); 16 } 17 if (System::which(IMAGE_TRANSFORM_IM_PATH . 'convert' . ((OS_WINDOWS) ? '.exe' : ''))) { 18 return true; 19 } 20 else { 21 return false; 22 } 23 } 8 24 9 25 /** … … 67 83 * @access private 68 84 */ 69 function setSrcInfos () {85 protected function setSrcInfos () { 70 86 if ($this->image != "") { 71 87 $exit = 0; //TODO: how ugly it is !! … … 105 121 return ''; 106 122 } 107 }123 } 108 124 109 125 ?> trunk/api/inc/imagetoolkit.php
r201 r211 1 1 <?php 2 2 3 ini_set('memory_limit', '32M');3 @ini_set('memory_limit', '32M'); 4 4 5 5 /** … … 7 7 * @abstract 8 8 */ 9 class ImageToolkit9 abstract class ImageToolkit 10 10 { 11 11 … … 14 14 /**-----------------------------------------------------------------------**/ 15 15 16 var $image; 17 var $imageWidth; 18 var $imageHeight; 19 var $imageType; 20 var $typeMime = ''; 21 22 var $imagDest; 23 var $imageDestWidth; 24 var $imageDestHeight; 25 var $mode; 26 16 protected $image; 17 protected $imageWidth; 18 protected $imageHeight; 19 protected $imageType; 20 protected $typeMime = ''; 21 22 protected $imagDest; 23 protected $imageDestWidth; 24 protected $imageDestHeight; 25 protected $mode; 26 27 /** 28 * Factory to create new instances of the right driver 29 * @param string $imagePath image path of the original image 30 * @param string $imageDriver driver to use 31 * @return ImageToolkit 32 */ 27 33 static function factory($imagePath, $imageDriver='') { 28 34 if ($imageDriver === '') { … … 47 53 * @param String $image Chemin complet vers l'image 48 54 */ 49 function ImageToolkit($image) {55 public function __construct($image) { 50 56 $this->image = $image; 51 $this->setSrcInfos ();57 $this->setSrcInfos(); 52 58 } 53 59 … … 56 62 * @return int Largeur finale de l'image redimensionnᅵe. 57 63 */ 58 function getImageDestWidth () {64 public function getImageDestWidth () { 59 65 return $this->imageDestWidth; 60 66 } … … 64 70 * @return int Hauteur finale de l'image redimensionnᅵe. 65 71 */ 66 function getImageDestHeight () {72 public function getImageDestHeight () { 67 73 return $this->imageDestHeight; 68 74 } 69 75 70 76 /** 71 * Ret ourne le type Mime de l'image72 * @return String Type mime de l'image73 */ 74 function getTypeMime () {77 * Returns the mime type of the image 78 * @return String Type mime type of the image 79 */ 80 public function getTypeMime () { 75 81 return $this->typeMime; 76 82 } 77 83 78 84 /** 79 * Fixe une taille finale maximale de redimensionnement.85 * Set a maximum resize size 80 86 * @param Int $dst_w Largeur maximale (px ou %) 81 87 * @param int $dst_h Hauteur maximale (px ou %) … … 83 89 * @param boolean $expand Allow resize of image 84 90 */ 85 function setDestSize ($dst_w, $dst_h, $mode='ratio', $expand=true) {91 public function setDestSize ($dst_w, $dst_h, $mode='ratio', $expand=true) { 86 92 $this->mode = $mode; 87 93 … … 171 177 172 178 /** 173 * Est ce qu'il faut redimentionner une image?179 * Does the image need to be resized ? 174 180 * @access private 175 181 * @return boolean 176 182 */ 177 function canResize () {183 protected function canResize () { 178 184 179 185 // the thumb exists ? … … 193 199 /** 194 200 * 201 * @return boolean 195 202 */ 196 203 function destBiggerThanFrom() { … … 206 213 * @return array associative array with color values in dezimal format (fields: 0->'red', 1->'green', 2->'blue') 207 214 */ 208 function hexToDecColor ($hex) {215 public static function hexToDecColor ($hex) { 209 216 $length = strlen($hex); 210 217 $color[] = hexdec(substr($hex, $length - 6, 2)); … … 219 226 * @access private 220 227 */ 221 function setSrcInfos () {222 }228 abstract protected function setSrcInfos() ; 229 223 230 /** 224 231 * @abstract 225 232 */ 226 function getImageDimensions($path) {227 }233 abstract public function getImageDimensions($path); 234 228 235 /** 229 236 * @abstract 230 237 */ 231 function createThumb ($img_dest) { 232 } 238 abstract public function createThumb ($img_dest) ; 239 240 /** 241 * @return boolean 242 */ 243 abstract public static function isAvailable(); 244 233 245 } 234 246
