From 7115a22bef9ead59732b473875f5cd38efee3b38 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 12 Aug 2010 20:20:22 -0400 Subject: [PATCH] Implement unsharpmask filtering in Ansel. --- ansel/config/conf.xml | 20 ++++++++++++++++++++ ansel/lib/Ansel.php | 3 ++- ansel/lib/ImageGenerator/Mini.php | 11 +++++++++++ ansel/lib/ImageGenerator/PolaroidThumb.php | 7 ++++++- ansel/lib/ImageGenerator/PrettyThumb.php | 9 ++++++++- ansel/lib/ImageGenerator/Screen.php | 11 +++++++++++ ansel/lib/ImageGenerator/ShadowSharpThumb.php | 9 +++++++++ ansel/lib/ImageGenerator/Thumb.php | 12 ++++++++++++ 8 files changed, 79 insertions(+), 3 deletions(-) diff --git a/ansel/config/conf.xml b/ansel/config/conf.xml index d617e8ba0..0e2cf1f7f 100644 --- a/ansel/config/conf.xml +++ b/ansel/config/conf.xml @@ -102,6 +102,16 @@ 150 150 + + + 0.7 + 1 + 0.05 + + + + @@ -112,6 +122,16 @@ width">800 600 + + + 0.5 + 1.2 + 0.05 + + + + diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index abc75614a..145915624 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -447,7 +447,8 @@ class Ansel static public function getImageObject($params = array()) { global $conf; - $context = array('tmpdir' => Horde::getTempDir()); + $context = array('tmpdir' => Horde::getTempDir(), + 'logger' => $GLOBALS['injector']->getInstance('Horde_Log_Logger')); if (!empty($conf['image']['convert'])) { $context['convert'] = $conf['image']['convert']; $context['identify'] = $conf['image']['identify']; diff --git a/ansel/lib/ImageGenerator/Mini.php b/ansel/lib/ImageGenerator/Mini.php index f00f9d8ae..6c8ca1c5f 100755 --- a/ansel/lib/ImageGenerator/Mini.php +++ b/ansel/lib/ImageGenerator/Mini.php @@ -16,6 +16,17 @@ class Ansel_ImageGenerator_Mini extends Ansel_ImageGenerator $this->_image->resize(min(50, $this->_dimensions['width']), min(50, $this->_dimensions['height']), true); + if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) { + try { + $this->_image->addEffect('Unsharpmask', + array('radius' => $GLOBALS['conf']['thumbnail']['radius'], + 'threshold' => $GLOBALS['conf']['thumbnail']['threshold'], + 'amount' => $GLOBALS['conf']['thumbnail']['amount'])); + $this->_image->applyEffects(); + } catch (Horde_Image_Exception $e) { + throw new Ansel_Exception($e); + } + } return $this->_image->getHordeImage(); } diff --git a/ansel/lib/ImageGenerator/PolaroidThumb.php b/ansel/lib/ImageGenerator/PolaroidThumb.php index b0bf83fe4..e7c134292 100644 --- a/ansel/lib/ImageGenerator/PolaroidThumb.php +++ b/ansel/lib/ImageGenerator/PolaroidThumb.php @@ -32,7 +32,12 @@ class Ansel_ImageGenerator_PolaroidThumb extends Ansel_ImageGenerator $this->_image->addEffect('PolaroidImage', array('background' => $styleDef['background'], 'padding' => 5)); - + if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) { + $this->_image->addEffect('Unsharpmask', + array('radius' => $GLOBALS['conf']['thumbnail']['radius'], + 'threshold' => $GLOBALS['conf']['thumbnail']['threshold'], + 'amount' => $GLOBALS['conf']['thumbnail']['amount'])); + } $this->_image->applyEffects(); } catch (Horde_Image_Exception $e) { throw new Ansel_Exception($e); diff --git a/ansel/lib/ImageGenerator/PrettyThumb.php b/ansel/lib/ImageGenerator/PrettyThumb.php index 5fe9df582..6bca68e1b 100644 --- a/ansel/lib/ImageGenerator/PrettyThumb.php +++ b/ansel/lib/ImageGenerator/PrettyThumb.php @@ -38,10 +38,17 @@ class Ansel_ImageGenerator_PrettyThumb extends Ansel_ImageGenerator 'padding' => 5, 'distance' => 5, 'fade' => 3)); + if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) { + $this->_image->addEffect('Unsharpmask', + array('radius' => $GLOBALS['conf']['thumbnail']['radius'], + 'threshold' => $GLOBALS['conf']['thumbnail']['threshold'], + 'amount' => $GLOBALS['conf']['thumbnail']['amount'])); + } + + $this->_image->applyEffects(); } catch (Horde_Image_Exception $e) { throw new Ansel_Exception($e); } - $this->_image->applyEffects(); return $this->_image->getHordeImage(); } diff --git a/ansel/lib/ImageGenerator/Screen.php b/ansel/lib/ImageGenerator/Screen.php index 448978aba..2084f65d5 100755 --- a/ansel/lib/ImageGenerator/Screen.php +++ b/ansel/lib/ImageGenerator/Screen.php @@ -16,6 +16,17 @@ class Ansel_ImageGenerator_Screen extends Ansel_ImageGenerator $this->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']), min($GLOBALS['conf']['screen']['height'], $this->_dimensions['height']), true); + if ($GLOBALS['conf']['screen']['unsharp'] && Ansel::isAvailable('Unsharpmask')) { + try { + $this->_image->addEffect('Unsharpmask', + array('radius' => $GLOBALS['conf']['screen']['radius'], + 'threshold' => $GLOBALS['conf']['screen']['threshold'], + 'amount' => $GLOBALS['conf']['screen']['amount'])); + $this->_image->applyEffects(); + } catch (Horde_Image $e) { + throw new Ansel_Exception($e); + } + } return $this->_image->getHordeImage(); } diff --git a/ansel/lib/ImageGenerator/ShadowSharpThumb.php b/ansel/lib/ImageGenerator/ShadowSharpThumb.php index bf9004fd1..241c4e2bb 100644 --- a/ansel/lib/ImageGenerator/ShadowSharpThumb.php +++ b/ansel/lib/ImageGenerator/ShadowSharpThumb.php @@ -36,6 +36,15 @@ class Ansel_ImageGenerator_ShadowSharpThumb extends Ansel_ImageGenerator 'padding' => 5, 'distance' => 8, 'fade' => 2)); + + if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) { + $this->_image->addEffect('Unsharpmask', + array('radius' => $GLOBALS['conf']['thumbnail']['radius'], + 'threshold' => $GLOBALS['conf']['thumbnail']['threshold'], + 'amount' => $GLOBALS['conf']['thumbnail']['amount'])); + $this->_image->applyEffects(); + } + $this->_image->applyEffects(); } catch (Horde_Image_Exception $e) { throw new Ansel_Exception($e); diff --git a/ansel/lib/ImageGenerator/Thumb.php b/ansel/lib/ImageGenerator/Thumb.php index f6203cd08..d563b4fd2 100755 --- a/ansel/lib/ImageGenerator/Thumb.php +++ b/ansel/lib/ImageGenerator/Thumb.php @@ -16,6 +16,18 @@ class Ansel_ImageGenerator_Thumb extends Ansel_ImageGenerator $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']), min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']), true); + if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) { + try { + $this->_image->addEffect('Unsharpmask', + array('radius' => $GLOBALS['conf']['thumbnail']['radius'], + 'threshold' => $GLOBALS['conf']['thumbnail']['threshold'], + 'amount' => $GLOBALS['conf']['thumbnail']['amount'])); + $this->_image->applyEffects(); + } catch (Horde_Image_Exception $e) { + throw new Ansel_Exception($e); + } + } + return $this->_image->getHordeImage(); } -- 2.11.0