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_Im_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: $ops = $geometry = $gravity = '';
40: if (isset($this->_params['gravity'])) {
41: $gravity = ' -gravity ' . $this->_params['gravity'];
42: }
43:
44: if (isset($this->_params['x']) && isset($this->_params['y'])) {
45: $geometry = ' -geometry +' . $this->_params['x'] . '+' . $this->_params['y'] . ' ';
46: }
47: if (isset($this->_params['compose'])) {
48: // The -matte ensures that the destination (background) image
49: // has an alpha channel - to avoid black holes in the image.
50: $compose = ' -compose ' . $this->_params['compose'] . ' -matte';
51: }
52:
53: foreach($this->_params['images'] as $image) {
54: $temp = $image->toFile();
55: $this->_image->addFileToClean($temp);
56: $ops .= ' ' . $temp . $gravity . $compose . ' -composite';
57: }
58: $this->_image->addOperation($geometry);
59: $this->_image->addPostSrcOperation($ops);
60:
61: return true;
62: }
63:
64: }