From d06c8b2415355f47a894a85fd62a7386fe806ef2 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 12 Aug 2010 14:18:43 -0400 Subject: [PATCH] Add an unsharpmask effect --- .../lib/Horde/Image/Effect/Im/Unsharpmask.php | 59 +++++++ .../lib/Horde/Image/Effect/Imagick/Unsharpmask.php | 68 +++++++ framework/Image/package.xml | 195 ++++++++++++--------- 3 files changed, 236 insertions(+), 86 deletions(-) create mode 100644 framework/Image/lib/Horde/Image/Effect/Im/Unsharpmask.php create mode 100644 framework/Image/lib/Horde/Image/Effect/Imagick/Unsharpmask.php diff --git a/framework/Image/lib/Horde/Image/Effect/Im/Unsharpmask.php b/framework/Image/lib/Horde/Image/Effect/Im/Unsharpmask.php new file mode 100644 index 000000000..39b4ec655 --- /dev/null +++ b/framework/Image/lib/Horde/Image/Effect/Im/Unsharpmask.php @@ -0,0 +1,59 @@ + + * @package Horde_Image + */ +class Horde_Image_Effect_Im_Unsharpmask extends Horde_Image_Effect +{ + /** + * + * Valid parameters: + * + * (float)radius - Thickness of the sharpened edge. Should be greater then + * 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. + * + * (float)amount - 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% + * + * (float)threshold - 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. + * + * (integer)channel - Which channel to apply the sharpening to. + * + * @var array + */ + protected $_params = array('radius' => 0.5, + 'amount' => 1, + 'threshold' => 0.05, + 'channel' => Imagick::CHANNEL_ALL); + + 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->addOperation("-unsharp {$this->_params['radius']}x{$this->_params['sigma']}+{$this->_params['amount']}+{$this->_params['threshold']}"); + + return true; + } + +} \ No newline at end of file diff --git a/framework/Image/lib/Horde/Image/Effect/Imagick/Unsharpmask.php b/framework/Image/lib/Horde/Image/Effect/Imagick/Unsharpmask.php new file mode 100644 index 000000000..e67d017ce --- /dev/null +++ b/framework/Image/lib/Horde/Image/Effect/Imagick/Unsharpmask.php @@ -0,0 +1,68 @@ + + * @package Horde_Image + */ +class Horde_Image_Effect_Imagick_Unsharpmask extends Horde_Image_Effect +{ + /** + * + * Valid parameters: + * + * (float)radius - Thickness of the sharpened edge. Should be greater then + * 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. + * + * (float)amount - 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% + * + * (float)threshold - 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. + * + * (integer)channel - Which channel to apply the sharpening to. + * + * @var array + */ + protected $_params = array('radius' => 0.5, + 'amount' => 1, + 'threshold' => 0.05, + 'channel' => Imagick::CHANNEL_ALL); + + 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']); + + try { + $this->_image->imagick->unsharpMaskImage( + $this->_params['radius'], + $this->_params['sigma'], + $this->_params['amount'], + $this->_params['threshold'], + $this->_params['channel']); + } catch (Imagick_Exception $e) { + throw new Horde_Image_Exception($e); + } + + return true; + } + +} \ No newline at end of file diff --git a/framework/Image/package.xml b/framework/Image/package.xml index 3611e301a..af1551457 100644 --- a/framework/Image/package.xml +++ b/framework/Image/package.xml @@ -1,8 +1,5 @@ - + Horde_Image pear.horde.org Horde Image API @@ -13,8 +10,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> * SVG * SWF * ImageMagick convert command line tool -* Imagick Extension - +* Imagick Extension Chuck Hagenbuch chuck @@ -27,8 +23,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> mrubinsk@horde.org yes - 2009-05-24 - + 2010-08-12 + 0.1.0 0.1.0 @@ -38,56 +34,63 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - Initial Horde 4 package + +Initial Horde 4 package + - + - - + - - + + + - - - - + + + + + - - + + - - - + + + + - - - - - - - - - - + - - - - + + + + + + + + + + + + + + + + @@ -95,18 +98,20 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - + - + + + + + + @@ -132,49 +137,51 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -189,7 +196,23 @@ http://pear.php.net/dtd/package-2.0.xsd"> 2004-01-01 LGPL - Initial release as a PEAR package + +Initial release as a PEAR package + + + + + 0.1.0 + 0.1.0 + + + alpha + alpha + + 2010-08-12 + LGPL + +Initial Horde 4 package -- 2.11.0