1: <?php
2: /**
3: * Image border decorator for the Horde_Image package.
4: *
5: * @author Chuck Hagenbuch <chuck@horde.org>
6: * @package Image
7: */
8: class Horde_Image_Effect_Border extends Horde_Image_Effect {
9:
10: /**
11: * Valid parameters for border decorators:
12: *
13: * padding - Pixels from the image edge that the border will start.
14: * borderColor - Border color. Defaults to black.
15: * fillColor - Color to fill the border with. Defaults to white.
16: * lineWidth - Border thickness, defaults to 1 pixel.
17: * roundWidth - Width of the corner rounding. Defaults to none.
18: *
19: * @var array
20: */
21: var $_params = array('padding' => 0,
22: 'borderColor' => 'black',
23: 'fillColor' => 'white',
24: 'lineWidth' => 1,
25: 'roundWidth' => 0);
26:
27: /**
28: * Draw the border.
29: *
30: * This draws the configured border to the provided image. Beware,
31: * that every pixel inside the border clipping will be overwritten
32: * with the background color.
33: */
34: function apply()
35: {
36: $o = $this->_params;
37:
38: $d = $this->_image->getDimensions();
39: $x = $o['padding'];
40: $y = $o['padding'];
41: $width = $d['width'] - (2 * $o['padding']);
42: $height = $d['height'] - (2 * $o['padding']);
43:
44: if ($o['roundWidth'] > 0) {
45: $this->_image->roundedRectangle($x, $y, $width, $height, $o['roundWidth'], $o['borderColor'], $o['fillColor']);
46: } else {
47: $this->_image->rectangle($x, $y, $width, $height, $o['borderColor'], $o['fillColor']);
48: }
49: }
50:
51: }
52: