Show
Ignore:
Timestamp:
01/27/2008 02:50:37 AM (10 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/Image.php

    r1814 r1827  
    5151        public function __construct($image, $config = NULL) 
    5252        { 
    53                 // Load configuration 
    54                 $this->config = (array) $config + Config::item('image'); 
     53                static $check; 
     54 
     55                // Make the check exactly once 
     56                ($check === NULL) and $check = function_exists('getimagesize'); 
     57 
     58                if ($check === FALSE) 
     59                        throw new Kohana_Exception('image.getimagesize_missing'); 
    5560 
    5661                // Check to make sure the image exists 
     
    5863                        throw new Kohana_Exception('image.file_not_found', $image); 
    5964 
     65                // Disable error reporting, to prevent PHP warnings 
     66                $ER = error_reporting(0); 
     67 
     68                // Fetch the image size and mime type 
     69                $image_info = getimagesize($image); 
     70 
     71                // Turn on error reporting again 
     72                error_reporting($ER); 
     73 
     74                // Make sure that the image is readable and valid 
     75                if ( ! is_array($image_info) OR count($image_info) < 3) 
     76                        throw new Kohana_Exception('image.file_unreadable', $image); 
     77 
    6078                // Check to make sure the image type is allowed 
    61                 if (($type = exif_imagetype($image)) == FALSE OR ! isset(Image::$allowed_types[$type])) 
     79                if ( ! isset(Image::$allowed_types[$image_info[2]])) 
    6280                        throw new Kohana_Exception('image.type_not_allowed', $image); 
    6381 
    64                 $this->image = str_replace('\\', '/', realpath($image)); 
     82                // Image has been validated, load it 
     83                $this->image = array 
     84                ( 
     85                        'file' => str_replace('\\', '/', realpath($image)), 
     86                        'width' => $image_info[0], 
     87                        'height' => $image_info[1], 
     88                        'type' => $image_info[2], 
     89                        'ext' => Image::$allowed_types[$image_info[2]], 
     90                        'mime' => $image_info['mime'] 
     91                ); 
     92 
     93                // Load configuration 
     94                $this->config = (array) $config + Config::item('image'); 
    6595 
    6696                try 
     
    247277        { 
    248278                // If no new image is defined, use the current image 
    249                 empty($new_image) and $new_image = $this->image; 
     279                empty($new_image) and $new_image = $this->image['file']; 
    250280 
    251281                // Separate the directory and filename