1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
<?php
/**
* Copyright 2009-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Image
*/
/**
* Simple composite effect for composing multiple images. This effect assumes
* that all images being passed in are already the desired size.
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @copyright 2009-2017 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Image
*/
class Horde_Image_Effect_Im_Composite extends Horde_Image_Effect
{
/**
* Valid parameters:
* - images: (array) An array of Horde_Image objects to overlay.
* - gravity: (string) The gravity describing the placement. One of None,
* Center, East, Forget, NorthEast, North, NorthWest,
* SouthEast, South, SouthWest, West
* - x and y: (integer) Coordinates for the overlay placement.
*
* EITHER gravity OR coordinates may be set. If both are provided, the
* behaviour is undefined.
*
* @var array
*/
protected $_params = array();
/**
* Applies the effect.
*/
public function apply()
{
$ops = $geometry = $gravity = '';
if (isset($this->_params['gravity'])) {
$gravity = ' -gravity ' . escapeshellarg($this->_params['gravity']);
}
if (isset($this->_params['x']) && isset($this->_params['y'])) {
$geometry = ' -geometry +' . (integer)$this->_params['x']
. '+' . (integer)$this->_params['y'] . ' ';
}
if (isset($this->_params['compose'])) {
// The -matte ensures that the destination (background) image has
// an alpha channel - to avoid black holes in the image.
$compose = ' -compose ' . escapeshellarg($this->_params['compose']) . ' -matte';
}
foreach ($this->_params['images'] as $image) {
$temp = $image->toFile();
$this->_image->addFileToClean($temp);
$ops .= ' ' . $temp . $gravity . $compose . ' -composite';
}
$this->_image->addOperation($geometry);
$this->_image->addPostSrcOperation($ops);
}
}
|