Updated testing for filter selects in reports
[ninja.git] / system / libraries / drivers / Image.php
blob4c5ccab77f9644639be2644115955387fd3620d1
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Image API driver.
5 * $Id: Image.php 3917 2009-01-21 03:06:22Z zombor $
7 * @package Image
8 * @author Kohana Team
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
15 protected $image;
17 // Reference to the temporary processing image
18 protected $tmp_image;
20 // Processing errors
21 protected $errors = array();
23 /**
24 * Executes a set of actions, defined in pairs.
26 * @param array actions
27 * @return boolean
29 public function execute($actions)
31 foreach ($actions as $func => $args)
33 if ( ! $this->$func($args))
34 return FALSE;
37 return TRUE;
40 /**
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
45 * @return void
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')
65 $geometry['top'] = 0;
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);
90 /**
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();
98 /**
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
105 * @return boolean
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
113 * @return boolean
115 abstract function flip($direction);
118 * Crop an image. Valid properties are: width, height, top, left.
120 * @param array new properties
121 * @return boolean
123 abstract function crop($properties);
126 * Resize an image. Valid properties are: width, height, and master.
128 * @param array new properties
129 * @return boolean
131 abstract public function resize($properties);
134 * Rotate an image. Valid amounts are -180 to 180.
136 * @param integer amount to rotate
137 * @return boolean
139 abstract public function rotate($amount);
142 * Sharpen and image. Valid amounts are 1 to 100.
144 * @param integer amount to sharpen
145 * @return boolean
147 abstract public function sharpen($amount);
149 } // End Image Driver