Add new config switches:
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 1 Jan 2011 16:36:01 +0000 (11:36 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 1 Jan 2011 16:36:01 +0000 (11:36 -0500)
Use sqare thumbnails vs older legacy mini thumbs (on by default)
Use a smart crop algorithm for generating square thumbnails (off by default)

ansel/config/conf.xml
ansel/lib/ImageGenerator/Mini.php
ansel/lib/ImageGenerator/SquareThumb.php

index 6ff172d..985fc25 100644 (file)
    themes and generation of 'pretty' thumbnails?  This can be a performance
     hit on some installations but is required for the generation of all but the
     most basic image thumbnails." required="false">false</configboolean>
+   <configboolean name="squaremini" desc="Should Ansel generate square
+   thumbnails for mini images? Doing so is recommended as this gives a cleaner
+   look to views. For those that prefer the look of the older mini images that
+   Ansel generated, uncheck this option">true</configboolean>
+   <configboolean name="smartcrop" desc="Should Ansel use a SmartCrop algorithm
+   if available when generating mini or square thumbnails? This gives a better
+   change that the crop will contain an interesting part of the image, but will
+   increase CPU usage during image generation."></configboolean>
    <configstring name="num_uploads" desc="How many photos should a user be
    allowed to upload at once?">5</configstring>
    <configstring name="font" required="false" desc="What font would you like
index 9b40e5f..2c3e99a 100755 (executable)
@@ -2,6 +2,11 @@
 /**
  * ImageGenerator to create the mini view.
  *
+ * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
@@ -13,11 +18,30 @@ class Ansel_ImageGenerator_Mini extends Ansel_ImageGenerator
      */
     protected function _create()
     {
-        $generator = Ansel_ImageGenerator::factory('SquareThumb', array('width' => min(50, $this->_dimensions['width']),
-                                                                        'height' => min(50, $this->_dimensions['height']),
-                                                                        'image' => $this->_image,
-                                                                        'style' => $this->_params['style']));
-        return $generator->create();
+        if ($GLOBALS['conf']['image']['squaremini']) {
+            $generator = Ansel_ImageGenerator::factory('SquareThumb', array('width' => min(50, $this->_dimensions['width']),
+                                                                            'height' => min(50, $this->_dimensions['height']),
+                                                                            'image' => $this->_image,
+                                                                            'style' => $this->_params['style']));
+            return $generator->create();
+        } else {
+            $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 37a82a0..2cc948c 100644 (file)
@@ -32,7 +32,7 @@ class Ansel_ImageGenerator_SquareThumb extends Ansel_ImageGenerator
         }
 
         // Use smartcrop algorithm if we have it, otherwise a plain center crop.
-        if (Ansel::isAvailable('SmartCrop')) {
+        if (Ansel::isAvailable('SmartCrop') && $GLOBALS['conf']['image']['smartcrop']) {
             $this->_image->addEffect('SmartCrop', array('width' => $size, 'height' => $size));
         } else {
             $this->_image->addEffect('CenterCrop', array('width' => $size, 'height' => $size));