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_Im_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:
43: public function apply()
44: {
45: /* Calculate appropriate sigma:
46: * Determines how the sharpening is graduated away from
47: * the center pixel of the sharpened edge. In general,
48: * if radius < 1, then sigma = radius else sigma = sqrt(radius)
49: */
50: $this->_params['sigma'] = ($this->_params['radius'] < 1) ?
51: $this->_params['radius'] : sqrt($this->_params['radius']);
52:
53: $this->_image->addPostSrcOperation("-unsharp {$this->_params['radius']}x{$this->_params['sigma']}+{$this->_params['amount']}+{$this->_params['threshold']}");
54:
55: return true;
56: }
57:
58: }