Changeset 1827
- Timestamp:
- 01/27/08 02:50:37 (7 months ago)
- Location:
- trunk/system
- Files:
-
- 4 modified
-
i18n/en_US/image.php (modified) (1 diff)
-
libraries/Image.php (modified) (3 diffs)
-
libraries/drivers/Image.php (modified) (2 diffs)
-
libraries/drivers/Image_ImageMagick.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/i18n/en_US/image.php
r1772 r1827 3 3 $lang = array 4 4 ( 5 'getimagesize_missing' => 'The Image library requires the <tt>getimagesize</tt> PHP function, which is not available in your installation.', 5 6 'driver_not_supported' => 'The requested Image driver, %s, was not found.', 7 'unsupported_method' => 'Your configured driver does not support the %s image transformation.', 8 'file_not_found' => 'The specified image, %s was not found. Please verify that images exist by using <tt>file_exists</tt> before manipulating them.', 9 'type_not_allowed' => 'The specified image, %s, is not an allowed image type.', 10 11 // ImageMagick specific messages 12 'imagemagick' => array 13 ( 14 'not_found' => 'The ImageMagick directory specified does not contain a required program, %s.', 15 ), 16 17 18 // GD specific messages 19 'gd' => array 20 ( 21 'requires_v2' => 'The Image library requires GD2. Please see http://php.net/gd_info for more information.', 22 ), 6 23 7 24 // CI's Image_lib stuff below -
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 -
trunk/system/libraries/drivers/Image.php
r1566 r1827 10 10 11 11 // Processing errors 12 protected $errors ;12 protected $errors = array(); 13 13 14 14 /** … … 28 28 return TRUE; 29 29 } 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(); 30 86 31 87 /** -
trunk/system/libraries/drivers/Image_ImageMagick.php
r1823 r1827 11 11 // Temporary image filename 12 12 protected $tmp_image; 13 14 // Processing errors15 protected $errors = array();16 13 17 14 /** … … 38 35 // Check to make sure the provided path is correct 39 36 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); 41 38 42 39 // Set the installation directory … … 50 47 public function process($image, $actions, $dir, $file) 51 48 { 49 // We only need the filename 50 $image = $image['file']; 51 52 52 // Unique temporary filename 53 53 $this->tmp_image = $dir.'k2img--'.sha1($dir.$file).substr($file, strrpos($file, '.')); … … 173 173 } 174 174 175 /**176 * Return the current width and height of the temporary image. This is mainly177 * needed for sanitizing the geometry.178 *179 * @return array width, height180 */181 175 protected function properties() 182 176 { 183 // Return the width and height as an array. Use with list()184 177 return explode(',', exec(escapeshellcmd($this->dir.'identify'.$this->ext).' -format '.escapeshellarg('%w,%h').' '.$this->cmd_image)); 185 178 } 186 179 187 /**188 * Sanitize and normalize a geometry array based on the temporary image189 * width and height. Valid properties are: width, height, top, left.190 *191 * @param array geometry properties192 * @return void193 */194 protected function sanitize_geometry( & $geometry)195 {196 list($width, $height) = $this->properties();197 198 // Turn off error reporting199 $reporting = error_reporting(0);200 201 // Width and height cannot exceed current image size202 $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 reporting232 error_reporting($reporting);233 }234 235 180 } // End Image ImageMagick Driver
