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