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.php

    r1566 r1827  
    1010 
    1111        // Processing errors 
    12         protected $errors; 
     12        protected $errors = array(); 
    1313 
    1414        /** 
     
    2828                return TRUE; 
    2929        } 
     30 
     31        /** 
     32         * Sanitize and normalize a geometry array based on the temporary image 
     33         * width and height. Valid properties are: width, height, top, left. 
     34         * 
     35         * @param   array  geometry properties 
     36         * @return  void 
     37         */ 
     38        protected function sanitize_geometry( & $geometry) 
     39        { 
     40                list($width, $height) = $this->properties(); 
     41 
     42                // Turn off error reporting 
     43                $reporting = error_reporting(0); 
     44 
     45                // Width and height cannot exceed current image size 
     46                $geometry['width']  = min($geometry['width'], $width); 
     47                $geometry['height'] = min($geometry['height'], $height); 
     48 
     49                switch($geometry['top']) 
     50                { 
     51                        case 'center': 
     52                                $geometry['top'] = floor(($height / 2) - ($geometry['height'] / 2)); 
     53                        break; 
     54                        case 'top': 
     55                                $geometry['top'] = 0; 
     56                        break; 
     57                        case 'bottom': 
     58                                $geometry['top'] = $height - $geometry['height']; 
     59                        break; 
     60                } 
     61 
     62                switch($geometry['left']) 
     63                { 
     64                        case 'center': 
     65                                $geometry['left'] = floor(($width / 2) - ($geometry['width'] / 2)); 
     66                        break; 
     67                        case 'left': 
     68                                $geometry['left'] = 0; 
     69                        break; 
     70                        case 'right': 
     71                                $geometry['left'] = $width - $geometry['height']; 
     72                        break; 
     73                } 
     74 
     75                // Restore error reporting 
     76                error_reporting($reporting); 
     77        } 
     78 
     79        /** 
     80         * Return the current width and height of the temporary image. This is mainly 
     81         * needed for sanitizing the geometry. 
     82         * 
     83         * @return  array  width, height 
     84         */ 
     85        abstract protected function properties(); 
    3086 
    3187        /**