1: <?php
2: /**
3: * Image effect for applying an unsharpmask.
4: *
5: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (LGPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9: *
10: * @author Michael J. Rubinsky <mrubinsk@horde.org>
11: * @package Image
12: */
13: class Horde_Image_Effect_Imagick_Unsharpmask extends Horde_Image_Effect
14: {
15: /**
16: *
17: * Valid parameters:
18: *
19: * (float)radius - Thickness of the sharpened edge. Should be greater then
20: * sigma (or 0, and imagick will attempt to auto choose).
21: * In general, radius should be roughly output dpi / 150.
22: * So for display purposes a radius of 0.5 is suggested.
23: *
24: * (float)amount - Amount of the difference between original and the
25: * blur image that gets added back to the original. Can be
26: * thought of as the "strength" of the effect. Too high
27: * may cause blocking of shadows and highlights. Given
28: * a decimal value indicating percentage, e.g. 1.2 = 120%
29: *
30: * (float)threshold - Determines how large the brightness delta between
31: * adjacent pixels needs to be to sharpen the edge.
32: * Larger values == less sharpening. Useful for
33: * preventing noisy images from being oversharpened.
34: *
35: * (integer)channel - Which channel to apply the sharpening to.
36: *
37: * @var array
38: */
39: protected $_params = array('radius' => 0.5,
40: 'amount' => 1,
41: 'threshold' => 0.05,
42: 'channel' => Imagick::CHANNEL_ALL);
43:
44: public function apply()
45: {
46: /* Calculate appropriate sigma:
47: * Determines how the sharpening is graduated away from
48: * the center pixel of the sharpened edge. In general,
49: * if radius < 1, then sigma = radius else sigma = sqrt(radius)
50: */
51: $this->_params['sigma'] = ($this->_params['radius'] < 1) ?
52: $this->_params['radius'] : sqrt($this->_params['radius']);
53:
54: try {
55: $this->_image->imagick->unsharpMaskImage(
56: $this->_params['radius'],
57: $this->_params['sigma'],
58: $this->_params['amount'],
59: $this->_params['threshold'],
60: $this->_params['channel']);
61: } catch (Imagick_Exception $e) {
62: throw new Horde_Image_Exception($e);
63: }
64:
65: return true;
66: }
67:
68: }