1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: class Horde_Image_Effect_Imagick_RoundCorners extends Horde_Image_Effect
11: {
12: 13: 14: 15: 16: 17: 18:
19: protected $_params = array('radius' => 10,
20: 'background' => 'none',
21: 'border' => 0,
22: 'bordercolor' => 'none');
23:
24: public function apply()
25: {
26: if (!method_exists($this->_image->imagick, 'roundCorners')) {
27: throw new Horde_Image_Exception('Your version of Imagick is not compiled against a recent enough ImageMagick library (> 6.2.8) to use the RoundCorners effect.');
28: }
29:
30: $round = $this->_params['radius'];
31: $result = $this->_image->imagick->roundCorners($round, $round);
32:
33:
34: if ($this->_params['bordercolor'] != 'none' &&
35: $this->_params['border'] > 0) {
36:
37: $size = $this->_image->getDimensions();
38:
39: $new = new Imagick();
40: $new->newImage($size['width'] + $this->_params['border'],
41: $size['height'] + $this->_params['border'],
42: $this->_params['bordercolor']);
43: $new->setImageFormat($this->_image->getType());
44:
45: $new->roundCorners($round, $round);
46: $new->compositeImage($this->_image->imagick, Imagick::COMPOSITE_OVER, 1, 1);
47: $this->_image->imagick->clear();
48: $this->_image->imagick->addImage($new);
49: $new->destroy();
50: }
51:
52:
53:
54:
55:
56: if ($this->_params['background'] != 'none') {
57: $size = $this->_image->getDimensions();
58: $new = new Imagick();
59: $new->newImage($size['width'],
60: $size['height'],
61: $this->_params['background']);
62: $new->setImageFormat($this->_image->getType());
63: $new->compositeImage($this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0);
64: $this->_image->imagick->clear();
65: $this->_image->imagick->addImage($new);
66: $new->destroy();
67: }
68:
69:
70: $this->_image->clearGeometry();
71:
72: return true;
73: }
74:
75: }