1: <?php
 2: /**
 3:  * Image border Effect for the Horde_Image package.
 4:  *
 5:  * @author  Chuck Hagenbuch <chuck@horde.org>
 6:  * @package Image
 7:  */
 8: class Horde_Image_Effect_Im_Border extends Horde_Image_Effect
 9: {
10:     /**
11:      * Valid parameters for border effects:
12:      *
13:      *   bordercolor     - Border color. Defaults to black.
14:      *   borderwidth     - Border thickness, defaults to 1 pixel.
15:      *   preserve        - Preserves the alpha transparency layer (if present)
16:      *
17:      * @var array
18:      */
19:     protected $_params = array('bordercolor' => 'black',
20:                                'borderwidth' => 1,
21:                                'preserve' => true);
22: 
23:     /**
24:      * Draw the border.
25:      *
26:      * This draws the configured border to the provided image. Beware,
27:      * that every pixel inside the border clipping will be overwritten
28:      * with the background color.
29:      */
30:     public function apply()
31:     {
32:         $this->_image->addPostSrcOperation(sprintf(
33:             "-bordercolor \"%s\" %s -border %s",
34:             $this->_params['bordercolor'],
35:             (!empty($this->_params['preserve']) ? '-compose Copy' : ''),
36:             $this->_params['borderwidth']));
37: 
38:         return true;
39:     }
40: 
41: }