1: <?php
2: /**
3: * Image effect for adding a drop shadow.
4: *
5: * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
6: *
7: * @author Michael J. Rubinsky <mrubinsk@horde.org>
8: * @package Image
9: */
10: class Horde_Image_Effect_Imagick_DropShadow extends Horde_Image_Effect
11: {
12: /**
13: * Valid parameters: Most are currently ignored for the im version
14: * of this effect.
15: *
16: * @TODO
17: *
18: * @var array
19: */
20: protected $_params = array('distance' => 5, // This is used as the x and y offset
21: 'width' => 2,
22: 'hexcolor' => '000000',
23: 'angle' => 215,
24: 'fade' => 3, // Sigma value
25: 'padding' => 0,
26: 'background' => 'none');
27:
28: /**
29: * Apply the effect.
30: *
31: * @return boolean
32: */
33: public function apply()
34: {
35: // There is what *I* call a bug in the magickwand interface of Im that
36: // Imagick is compiled against. The X and Y parameters are ignored, and
37: // the distance of the shadow is determined *solely* by the sigma value
38: // which makes it pretty much impossible to have Imagick shadows look
39: // identical to Im shadows...
40: $shadow = $this->_image->imagick->clone();
41: $shadow->setImageBackgroundColor(new ImagickPixel('black'));
42: $shadow->shadowImage(80, $this->_params['fade'],
43: $this->_params['distance'],
44: $this->_params['distance']);
45:
46: $shadow->compositeImage($this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0);
47:
48: if ($this->_params['padding']) {
49: $shadow->borderImage($this->_params['background'],
50: $this->_params['padding'],
51: $this->_params['padding']);
52: }
53: $this->_image->imagick->clear();
54: $this->_image->imagick->addImage($shadow);
55: $shadow->destroy();
56:
57: $this->_image->clearGeometry();
58:
59: return true;
60: }
61:
62: }