1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
5 * $Id: Image.php 3917 2009-01-21 03:06:22Z zombor $
9 * @copyright (c) 2007-2008 Kohana Team
10 * @license http://kohanaphp.com/license.html
12 abstract class Image_Driver
{
14 // Reference to the current image
17 // Reference to the temporary processing image
21 protected $errors = array();
24 * Executes a set of actions, defined in pairs.
26 * @param array actions
29 public function execute($actions)
31 foreach ($actions as $func => $args)
33 if ( ! $this->$func($args))
41 * Sanitize and normalize a geometry array based on the temporary image
42 * width and height. Valid properties are: width, height, top, left.
44 * @param array geometry properties
47 protected function sanitize_geometry( & $geometry)
49 list($width, $height) = $this->properties();
51 // Turn off error reporting
52 $reporting = error_reporting(0);
54 // Width and height cannot exceed current image size
55 $geometry['width'] = min($geometry['width'], $width);
56 $geometry['height'] = min($geometry['height'], $height);
58 // Set standard coordinates if given, otherwise use pixel values
59 if ($geometry['top'] === 'center')
61 $geometry['top'] = floor(($height / 2) - ($geometry['height'] / 2));
63 elseif ($geometry['top'] === 'top')
67 elseif ($geometry['top'] === 'bottom')
69 $geometry['top'] = $height - $geometry['height'];
72 // Set standard coordinates if given, otherwise use pixel values
73 if ($geometry['left'] === 'center')
75 $geometry['left'] = floor(($width / 2) - ($geometry['width'] / 2));
77 elseif ($geometry['left'] === 'left')
79 $geometry['left'] = 0;
81 elseif ($geometry['left'] === 'right')
83 $geometry['left'] = $width - $geometry['height'];
86 // Restore error reporting
87 error_reporting($reporting);
91 * Return the current width and height of the temporary image. This is mainly
92 * needed for sanitizing the geometry.
94 * @return array width, height
96 abstract protected function properties();
99 * Process an image with a set of actions.
101 * @param string image filename
102 * @param array actions to execute
103 * @param string destination directory path
104 * @param string destination filename
107 abstract public function process($image, $actions, $dir, $file);
110 * Flip an image. Valid directions are horizontal and vertical.
112 * @param integer direction to flip
115 abstract function flip($direction);
118 * Crop an image. Valid properties are: width, height, top, left.
120 * @param array new properties
123 abstract function crop($properties);
126 * Resize an image. Valid properties are: width, height, and master.
128 * @param array new properties
131 abstract public function resize($properties);
134 * Rotate an image. Valid amounts are -180 to 180.
136 * @param integer amount to rotate
139 abstract public function rotate($amount);
142 * Sharpen and image. Valid amounts are 1 to 100.
144 * @param integer amount to sharpen
147 abstract public function sharpen($amount);
149 } // End Image Driver