Changeset 1827 for trunk/system/libraries/drivers/Image_ImageMagick.php
- Timestamp:
- 01/27/2008 02:50:37 AM (12 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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
