Changeset 1827 for trunk/system/libraries/Image.php
- Timestamp:
- 01/27/2008 02:50:37 AM (10 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/Image.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Image.php
r1814 r1827 51 51 public function __construct($image, $config = NULL) 52 52 { 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'); 55 60 56 61 // Check to make sure the image exists … … 58 63 throw new Kohana_Exception('image.file_not_found', $image); 59 64 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 60 78 // 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]])) 62 80 throw new Kohana_Exception('image.type_not_allowed', $image); 63 81 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'); 65 95 66 96 try … … 247 277 { 248 278 // 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']; 250 280 251 281 // Separate the directory and filename
