Luxbum.net - Script de galerie photo

Changeset 211

Show
Ignore:
Timestamp:
05/27/07 17:27:34 (1 year ago)
Author:
nicolas
Message:

Drivers pour la génération des images en joli php5

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/api/inc/imagetoolkit.gd.php

    r207 r211  
    88class ImageToolkitGD extends ImageToolkit 
    99{ 
     10    
     11   /** 
     12    * @return boolean 
     13    */ 
     14   public static function isAvailable() { 
     15       return extension_loaded("gd"); 
     16   } 
    1017 
    1118   /** 
     
    1421    * @return Handler 
    1522    */ 
    16    function imageCreateFromType () { 
     23   private function imageCreateFromType () { 
    1724 
    1825      switch ($this->imageType) { 
     
    3946 
    4047   /** 
    41     * Ecrit l'image redimensionnᅵe. 
     48    * Write the new image 
    4249    * @access private 
    4350    */ 
    44    function imageWriteFromType ($image, $quality) { 
     51   private function imageWriteFromType ($image, $quality) { 
    4552 
    4653      switch ($this->imageType){ 
     
    6067 
    6168   /** 
    62     * Remplit les champs principaux de la classe. 
     69    * Fill in main fields of the class 
    6370    *  
    6471    * @access private 
    6572    */ 
    66    function setSrcInfos () { 
     73   protected function setSrcInfos () { 
    6774      if ($this->image != "") {          
    6875         // Lit les dimensions de l'image 
     
    7986    * @access static 
    8087    */ 
    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]); 
    8592      } 
    8693      return ''; 
     
    8895 
    8996   /** 
    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) { 
    95101      $this->imageDest = $img_dest; 
    96102 
    97       // Crᅵer la vignette ? 
     103      // Create the resized image ? 
    98104      if ($this->canResize ()) { 
    99105 
    100          // Copie dedans l'image initiale redimensionnᅵ
    101          $srcHandler = $this->ImageCreateFromType ($this->image, $this->imageType); 
     106         // Loads image from source fil
     107         $srcHandler = $this->ImageCreateFromType($this->image, $this->imageType); 
    102108 
    103109 
    104110         /* GD 2 */ 
    105111         if ($this->gdVersion() == 2) { 
    106  
    107             // Crᅵe une image vierge aux bonnes dimensions 
    108112            $destHandler = ImageCreateTrueColor ($this->imageDestWidth, $this->imageDestHeight); 
    109113            ImageCopyResampled ($destHandler, $srcHandler, 0, 0, $this->decalW, $this->decalH, $this->imageDestWidth, $this->imageDestHeight, $this->cropW, $this->cropH); 
     
    112116         /* GD 1 */ 
    113117         else { 
    114  
    115             // Crᅵe une image vierge aux bonnes dimensions 
    116118            $destHandler = ImageCreate ($this->imageDestWidth, $this->imageDestHeight); 
    117119            imagecopyresized ($destHandler, $srcHandler, 0, 0, $this->decalW, $this->decalH, $this->imageDestWidth, $this->imageDestHeight, $this->cropW, $this->cropH); 
    118120         } 
    119121 
    120          // Sauve la nouvelle image 
     122         // Save the new image 
    121123         if (!$this->ImageWriteFromType ($destHandler, 95)) { 
    122124            throw new Pluf_HTTP_ImageException(); 
    123125         } 
    124          @chmod ($this->imageDest, 0777); 
    125  
    126          // Dᅵtruis les tampons 
     126         @chmod ($this->imageDest, 0775); 
     127 
     128         // Destroy image handle 
    127129         ImageDestroy ($destHandler); 
    128130         ImageDestroy ($srcHandler); 
     
    132134 
    133135   /** 
    134     * Retourne la version exacte de GD 
     136    * Get the exact GD installed version 
    135137    * @return Version exacte de GD 
    136138    */ 
    137    function gdVersionExact ()  { 
     139   public static function gdVersionExact ()  { 
    138140      static $gd_version_number = null; 
    139141      if ($gd_version_number === null) { 
     
    162164    * @return 1 ou 2 pour GD1 ou GD2 
    163165    */ 
    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')) { 
    167169         return; 
    168170      } 
  • trunk/api/inc/imagetoolkit.imagemagick.php

    r209 r211  
    66class ImageToolkitImageMagick extends ImageToolkit { 
    77   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   } 
    824 
    925   /** 
     
    6783    * @access private 
    6884    */ 
    69    function setSrcInfos () { 
     85   protected function setSrcInfos () { 
    7086      if ($this->image != "") { 
    7187         $exit = 0; //TODO: how ugly it is !! 
     
    105121      return ''; 
    106122   } 
    107  
     123
    108124 
    109125?> 
  • trunk/api/inc/imagetoolkit.php

    r201 r211  
    11<?php 
    22 
    3 ini_set ('memory_limit', '32M');  
     3@ini_set('memory_limit', '32M');  
    44 
    55/** 
     
    77 * @abstract 
    88 */ 
    9 class ImageToolkit 
     9abstract class ImageToolkit 
    1010{ 
    1111 
     
    1414   /**-----------------------------------------------------------------------**/ 
    1515 
    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    */ 
    2733   static function factory($imagePath, $imageDriver='') { 
    2834      if ($imageDriver === '') { 
     
    4753    * @param String $image Chemin complet vers l'image 
    4854    */ 
    49    function ImageToolkit ($image) { 
     55   public function __construct($image) { 
    5056      $this->image = $image; 
    51       $this->setSrcInfos (); 
     57      $this->setSrcInfos(); 
    5258   } 
    5359 
     
    5662    * @return int Largeur finale de l'image redimensionnᅵe. 
    5763    */ 
    58    function getImageDestWidth () { 
     64   public function getImageDestWidth () { 
    5965      return $this->imageDestWidth; 
    6066   } 
     
    6470    * @return int Hauteur finale de l'image redimensionnᅵe. 
    6571    */ 
    66    function getImageDestHeight () { 
     72   public function getImageDestHeight () { 
    6773      return $this->imageDestHeight; 
    6874   } 
    6975    
    7076   /** 
    71     * Retourne le type Mime de l'image 
    72     * @return String Type mime de l'image 
    73     */ 
    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 () { 
    7581      return $this->typeMime; 
    7682   } 
    7783 
    7884   /** 
    79     * Fixe une taille finale maximale de redimensionnement. 
     85    * Set a maximum resize size 
    8086    * @param Int $dst_w Largeur maximale (px ou %) 
    8187    * @param int $dst_h Hauteur maximale (px ou %) 
     
    8389    * @param boolean $expand Allow resize of image 
    8490   */ 
    85    function setDestSize ($dst_w, $dst_h, $mode='ratio', $expand=true) { 
     91   public function setDestSize ($dst_w, $dst_h, $mode='ratio', $expand=true) { 
    8692      $this->mode = $mode; 
    8793 
     
    171177 
    172178   /** 
    173     * Est ce qu'il faut redimentionner une image
     179    * Does the image need to be resized
    174180    * @access private 
    175181    * @return boolean 
    176182    */ 
    177    function canResize () { 
     183   protected function canResize () { 
    178184 
    179185      // the thumb exists ? 
     
    193199   /** 
    194200    * 
     201    * @return boolean 
    195202    */ 
    196203   function destBiggerThanFrom() { 
     
    206213    * @return array associative array with color values in dezimal format (fields: 0->'red', 1->'green', 2->'blue') 
    207214    */ 
    208    function hexToDecColor ($hex) { 
     215   public static function hexToDecColor ($hex) { 
    209216      $length = strlen($hex); 
    210217      $color[] = hexdec(substr($hex, $length - 6, 2)); 
     
    219226    * @access private 
    220227    */ 
    221    function setSrcInfos () { 
    222    } 
     228   abstract protected function setSrcInfos() ; 
     229    
    223230   /** 
    224231    * @abstract 
    225232    */ 
    226    function getImageDimensions($path) { 
    227    } 
     233   abstract public function getImageDimensions($path); 
     234    
    228235   /** 
    229236    * @abstract 
    230237    */ 
    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    
    233245} 
    234246