1: <?php
2: /**
3: * The Horde_Image_Effect parent class defines a general API for
4: * ways to apply effects to Horde_Image objects.
5: *
6: * @author Chuck Hagenbuch <chuck@horde.org>
7: * @author Michael J. Rubinsky <mrubinsk@horde.org>
8: * @package Image
9: */
10: class Horde_Image_Effect
11: {
12: /**
13: * Effect parameters.
14: *
15: * @var array
16: */
17: protected $_params = array();
18:
19: /**
20: * The bound Horde_Image object
21: *
22: * @var Horde_Image
23: */
24: protected $_image = null;
25:
26: protected $_logger;
27:
28: /**
29: * Effect constructor.
30: *
31: * @param array $params Any parameters for the effect. Parameters are
32: * documented in each subclass.
33: */
34: public function __construct($params = array())
35: {
36: foreach ($params as $key => $val) {
37: $this->_params[$key] = $val;
38: }
39: }
40:
41: /**
42: * Bind this effect to a Horde_Image object.
43: *
44: * @param Horde_Image $image The Horde_Image object
45: *
46: * @TODO: Can we get rid of the reference here? (Looks OK for GD, but need
47: * to test im/imagick also).
48: *
49: * @return void
50: */
51: public function setImageObject(&$image)
52: {
53: $this->_image = &$image;
54: }
55:
56: public function setLogger($logger)
57: {
58: $this->_logger = $logger;
59: }
60:
61: static public function factory($type, $driver, $params)
62: {
63: if (is_array($type)) {
64: list($app, $type) = $type;
65: }
66:
67: // First check for a driver specific effect, if we can't find one,
68: // assume there is a vanilla effect object around.
69: $class = 'Horde_Image_Effect_' . $driver . '_' . $type;
70: $vclass = 'Horde_Image_Effect_' . $type;
71: if (!class_exists($class) && !class_exists($vclass)) {
72: if (!empty($app)) {
73: $path = $GLOBALS['registry']->get('fileroot', $app) . '/lib/Image/Effect/' . $driver . '/' . $type . '.php';
74: } else {
75: $path = 'Horde/Image/Effect/' . $driver . '/' . $type . '.php';
76: }
77:
78: @include_once $path;
79: if (!class_exists($class)) {
80: if (!empty($app)) {
81: $path = $GLOBALS['registry']->get('fileroot', $app) . '/lib/Image/Effect/' . $type . '.php';
82: } else {
83: $path = 'Horde/Image/Effect/' . $type . '.php';
84: }
85: $class = $vclass;
86: @include_once $path;
87: }
88: }
89:
90: if (class_exists($class)) {
91: $effect = new $class($params);
92: } else {
93: $params['logger']->err(sprintf("Horde_Image_Effect %s for %s driver not found.", $type, $driver));
94: throw new Horde_Image_Exception(sprintf("Horde_Image_Effect %s for %s driver not found.", $type, $driver));
95: }
96:
97: if (!empty($params['logger'])) {
98: $effect->setLogger($params['logger']);
99: }
100:
101: return $effect;
102: }
103:
104: }