1: <?php
2: /**
3: * Simple composite effect for composing multiple images. This effect assumes
4: * that all images being passed in are already the desired size.
5: *
6: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
7: *
8: * @author Michael J. Rubinsky <mrubinsk@horde.org>
9: * @package Image
10: */
11: class Horde_Image_Effect_Imagick_Composite extends Horde_Image_Effect
12: {
13: /**
14: * Valid parameters for border effects:
15: *
16: * 'images' - an array of Horde_Image objects to overlay.
17: *
18: * ...and ONE of the following. If both are provided, the behaviour is
19: * undefined.
20: *
21: * 'gravity' - the ImageMagick gravity constant describing placement
22: * (IM driver only so far, not imagick)
23: *
24: * 'x' and 'y' - coordinates for the overlay placement.
25: *
26: * @var array
27: */
28: protected $_params = array();
29:
30: /**
31: * Draw the border.
32: *
33: * This draws the configured border to the provided image. Beware,
34: * that every pixel inside the border clipping will be overwritten
35: * with the background color.
36: */
37: public function apply()
38: {
39: foreach ($this->_params['images'] as $image) {
40: $topimg = new Imagick();
41: $topimg->clear();
42: $topimg->readImageBlob($image->raw());
43:
44: /* Calculate center for composite (gravity center)*/
45: $geometry = $this->_image->imagick->getImageGeometry();
46: $x = $geometry['width'] / 2;
47: $y = $geometry['height'] / 2;
48:
49: if (isset($this->_params['x']) && isset($this->_params['y'])) {
50: $x = $this->_params['x'];
51: $y = $this->_params['y'];
52: }
53: $this->_image->_imagick->compositeImage($topimg, Imagick::COMPOSITE_OVER, $x, $y);
54: }
55: return true;
56: }
57:
58: }