Implement unsharpmask filtering in Ansel.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 13 Aug 2010 00:20:22 +0000 (20:20 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 13 Aug 2010 00:21:17 +0000 (20:21 -0400)
ansel/config/conf.xml
ansel/lib/Ansel.php
ansel/lib/ImageGenerator/Mini.php
ansel/lib/ImageGenerator/PolaroidThumb.php
ansel/lib/ImageGenerator/PrettyThumb.php
ansel/lib/ImageGenerator/Screen.php
ansel/lib/ImageGenerator/ShadowSharpThumb.php
ansel/lib/ImageGenerator/Thumb.php

index d617e8b..0e2cf1f 100644 (file)
    <configstring name="width" desc="Thumbnail width">150</configstring>
    <configstring name="height" desc="Thumbnail
    height">150</configstring>
+   <configswitch name="unsharp" desc="Should Horde apply an unsharpmask filter
+   to the image after it's resized?">
+    <case name="true" desc="Yes">
+      <configstring name="radius" desc="Radius">0.7</configstring>
+      <configstring name="amount" desc="Amount">1</configstring>
+      <configstring name="threshold" desc="Threshold">0.05</configstring>
+    </case>
+    <case name="false" desc="No" />
+   </configswitch>
+
   </configsection>
  </configtab>
 
    width">800</configstring>
    <configstring name="height" desc="Screen photo
    height">600</configstring>
+   <configswitch name="unsharp" desc="Should Horde apply an unsharpmask filter
+   to the image after it's resized?">
+    <case name="true" desc="Yes">
+      <configstring name="radius" desc="Radius">0.5</configstring>
+      <configstring name="amount" desc="Amount">1.2</configstring>
+      <configstring name="threshold" desc="Threshold">0.05</configstring>
+    </case>
+    <case name="false" desc="No" />
+   </configswitch>
+
   </configsection>
  </configtab>
 
index abc7561..1459156 100644 (file)
@@ -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'];
index f00f9d8..6c8ca1c 100755 (executable)
@@ -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();
     }
index b0bf83f..e7c1342 100644 (file)
@@ -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);
index 5fe9df5..6bca68e 100644 (file)
@@ -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();
         }
index 448978a..2084f65 100755 (executable)
@@ -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();
     }
index bf9004f..241c4e2 100644 (file)
@@ -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);
index f6203cd..d563b4f 100755 (executable)
@@ -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();
     }