Show
Ignore:
Timestamp:
01/27/2008 02:50:37 AM (12 months ago)
Author:
Shadowhand
Message:

Updates to Image:

  • Moved sanitize_geometry to Image_Driver
  • Made properties() an abstract method
  • Updated language files with new and missing messages
  • Removed exif_imagetype() usage in favor of getimagesize(), which is more common and provides more information
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/drivers/Image_ImageMagick.php

    r1823 r1827  
    1111        // Temporary image filename 
    1212        protected $tmp_image; 
    13  
    14         // Processing errors 
    15         protected $errors = array(); 
    1613 
    1714        /** 
     
    3835                // Check to make sure the provided path is correct 
    3936                if ( ! file_exists(realpath($config['directory']).'/convert'.$this->ext)) 
    40                         throw new Kohana_Exception('image.imagemagick.not_found'); 
     37                        throw new Kohana_Exception('image.imagemagick.not_found', 'convert'.$this->ext); 
    4138 
    4239                // Set the installation directory 
     
    5047        public function process($image, $actions, $dir, $file) 
    5148        { 
     49                // We only need the filename 
     50                $image = $image['file']; 
     51 
    5252                // Unique temporary filename 
    5353                $this->tmp_image = $dir.'k2img--'.sha1($dir.$file).substr($file, strrpos($file, '.')); 
     
    173173        } 
    174174 
    175         /** 
    176          * Return the current width and height of the temporary image. This is mainly 
    177          * needed for sanitizing the geometry. 
    178          * 
    179          * @return  array  width, height 
    180          */ 
    181175        protected function properties() 
    182176        { 
    183                 // Return the width and height as an array. Use with list() 
    184177                return explode(',', exec(escapeshellcmd($this->dir.'identify'.$this->ext).' -format '.escapeshellarg('%w,%h').' '.$this->cmd_image)); 
    185178        } 
    186179 
    187         /** 
    188          * Sanitize and normalize a geometry array based on the temporary image 
    189          * width and height. Valid properties are: width, height, top, left. 
    190          * 
    191          * @param   array  geometry properties 
    192          * @return  void 
    193          */ 
    194         protected function sanitize_geometry( & $geometry) 
    195         { 
    196                 list($width, $height) = $this->properties(); 
    197  
    198                 // Turn off error reporting 
    199                 $reporting = error_reporting(0); 
    200  
    201                 // Width and height cannot exceed current image size 
    202                 $geometry['width']  = min($geometry['width'], $width); 
    203                 $geometry['height'] = min($geometry['height'], $height); 
    204  
    205                 switch($geometry['top']) 
    206                 { 
    207                         case 'center': 
    208                                 $geometry['top'] = floor(($height / 2) - ($geometry['height'] / 2)); 
    209                         break; 
    210                         case 'top': 
    211                                 $geometry['top'] = 0; 
    212                         break; 
    213                         case 'bottom': 
    214                                 $geometry['top'] = $height - $geometry['height']; 
    215                         break; 
    216                 } 
    217  
    218                 switch($geometry['left']) 
    219                 { 
    220                         case 'center': 
    221                                 $geometry['left'] = floor(($width / 2) - ($geometry['width'] / 2)); 
    222                         break; 
    223                         case 'left': 
    224                                 $geometry['left'] = 0; 
    225                         break; 
    226                         case 'right': 
    227                                 $geometry['left'] = $width - $geometry['height']; 
    228                         break; 
    229                 } 
    230  
    231                 // Restore error reporting 
    232                 error_reporting($reporting); 
    233         } 
    234  
    235180} // End Image ImageMagick Driver