Ansel_ImageView -> Ansel_ImageGenerator
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 19 Jul 2010 17:35:29 +0000 (13:35 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 19 Jul 2010 17:35:29 +0000 (13:35 -0400)
27 files changed:
ansel/image.php
ansel/lib/Gallery.php
ansel/lib/Image.php
ansel/lib/ImageGenerator.php [new file with mode: 0644]
ansel/lib/ImageGenerator/Mini.php [new file with mode: 0755]
ansel/lib/ImageGenerator/PlainStack.php [new file with mode: 0644]
ansel/lib/ImageGenerator/PolaroidStack.php [new file with mode: 0644]
ansel/lib/ImageGenerator/PolaroidThumb.php [new file with mode: 0644]
ansel/lib/ImageGenerator/PrettyThumb.php [new file with mode: 0644]
ansel/lib/ImageGenerator/RoundedStack.php [new file with mode: 0644]
ansel/lib/ImageGenerator/Screen.php [new file with mode: 0755]
ansel/lib/ImageGenerator/ShadowSharpThumb.php [new file with mode: 0644]
ansel/lib/ImageGenerator/Thumb.php [new file with mode: 0755]
ansel/lib/ImageView.php [deleted file]
ansel/lib/ImageView/Mini.php [deleted file]
ansel/lib/ImageView/PlainStack.php [deleted file]
ansel/lib/ImageView/PolaroidStack.php [deleted file]
ansel/lib/ImageView/PolaroidThumb.php [deleted file]
ansel/lib/ImageView/PrettyThumb.php [deleted file]
ansel/lib/ImageView/RoundedStack.php [deleted file]
ansel/lib/ImageView/Screen.php [deleted file]
ansel/lib/ImageView/ShadowSharpThumb.php [deleted file]
ansel/lib/ImageView/Thumb.php [deleted file]
ansel/lib/View/Base.php
ansel/templates/image/crop_image.inc
ansel/templates/image/edit_image.inc
ansel/templates/image/resize_image.inc

index 5c55eb8..d87a71c 100644 (file)
@@ -277,7 +277,7 @@ case 'save':
 case 'editimage':
 case 'cropedit':
 case 'resizeedit':
-    $imageview_url = Ansel::getUrlFor('view', array_merge(
+    $ImageGenerator_url = Ansel::getUrlFor('view', array_merge(
                                      array('gallery' => $gallery_id,
                                            'image' => $image_id,
                                            'view' => 'Image',
@@ -304,7 +304,7 @@ case 'resizeedit':
                             'horde.error');
 
         /* Return to the image view. */
-        header('Location: ' . $imageview_url);
+        header('Location: ' . $ImageGenerator_url);
         exit;
     }
 
index cce5306..8c9f87f 100644 (file)
@@ -627,7 +627,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
             // Don't already have one, must generate it.
             $params = array('gallery' => $this, 'style' => $gal_style);
             try {
-                $iview = Ansel_ImageView::factory($gal_style['default_galleryimage_type'], $params);
+                $iview = Ansel_ImageGenerator::factory($gal_style['default_galleryimage_type'], $params);
                 $img = $iview->create();
 
                 // Note the gallery_id is negative for generated stacks
@@ -913,7 +913,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
             // Manually convert the charset since we're not going through save()
             // @TODO: Look at this usage - maybe each app's share object should
             //  have this method or just keep it public?
-            $data = $this->getshareOb()->toDriverChaset(array($driver_key => $value));
+            $data = $this->getshareOb()->toDriverCharset(array($driver_key => $value));
             $query = $db->prepare('UPDATE ' . $this->getShareOb()->getTable() . ' SET ' . $driver_key . ' = ? WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
             if ($GLOBALS['conf']['ansel_cache']['usecache']) {
                 $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->id);
index f4471a3..a5a0c7d 100644 (file)
@@ -401,23 +401,23 @@ class Ansel_Image Implements Iterator
         }
 
         try {
-           $iview = Ansel_ImageView::factory($viewType, array('image' => $this, 'style' => $style));
+           $iview = Ansel_ImageGenerator::factory($viewType, array('image' => $this, 'style' => $style));
         } catch (Ansel_Exception $e) {
             // It could be we don't support the requested effect, try
             // ansel_default before giving up.
             if ($view == 'prettythumb') {
                 // If we still fail, the exception gets thrown up the chain.
-                $iview = Ansel_ImageView::factory('Thumb', array('image' => $this, 'style' => 'ansel_default'));
+                $iview = Ansel_ImageGenerator::factory('Thumb', array('image' => $this, 'style' => 'ansel_default'));
             } else {
                 // If it wasn't a prettythumb, then something else must be wrong
                 throw $e;
             }
         }
 
-        /* Create the ImageView */
+        /* Create the ImageGenerator */
         $iview->create();
 
-        /* Cache the data from the new imageview */
+        /* Cache the data from the new ImageGenerator */
         try {
             $this->_data[$vHash] = $this->_image->raw();
         } catch (Horde_Image_Exception $e) {
diff --git a/ansel/lib/ImageGenerator.php b/ansel/lib/ImageGenerator.php
new file mode 100644 (file)
index 0000000..1d47192
--- /dev/null
@@ -0,0 +1,196 @@
+<?php
+/**
+ * Class to abstract the creation of various image views.
+ *
+ * Copyright 2007-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.
+ *
+ * Copyright 2007-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
+ */
+class Ansel_ImageGenerator
+{
+    /**
+     * Ansel_Image object that this view is created from.
+     *
+     * @var Ansel_Image
+     */
+    protected $_image = null;
+
+    /**
+     * Parameters for this view
+     *
+     * @var array
+     */
+    protected $_params = array();
+
+    /**
+     * Image dimensions
+     *
+     * @var array
+     */
+    protected $_dimensions = array();
+
+    /**
+     * Cache the style information array
+     *
+     * @var array
+     */
+    protected $_style = array();
+
+    /**
+     * Array of required, supported features for this ImageGenerator to work
+     *
+     * @var array
+     */
+    public  $need = array();
+
+    /**
+     * Const'r
+     *
+     * @return Horde_ImageGenerator
+     */
+    public function __construct($params)
+    {
+        $this->_params = $params;
+        if (!empty($params['image'])) {
+            $this->_image = $params['image'];
+        }
+        $this->_style = $params['style'];
+    }
+
+    /**
+     * Create and cache the view.
+     *
+     * @return mixed  Views used as gallery key images return Horde_Image,
+     *                other views return boolean
+     */
+    public function create()
+    {
+        if (!empty($this->_image)) {
+            // Use Horde_Image since we don't know at this point which
+            // view we have loaded.
+            $img = $this->_image->getHordeImage();
+            $this->_dimensions = $img->getDimensions();
+        }
+
+        return $this->_create();
+    }
+
+    /**
+     * Horde_ImageGenerator factory
+     *
+     * @param string $type   The type of concrete instance to return.
+     * @param array $params  Additional parameters needed for the instance.
+     *
+     * @return Ansel_ImageGenerator
+     * @throws Ansel_Exception
+     */
+    function factory($type, $params = array())
+    {
+        $type = basename($type);
+        $class = 'Ansel_ImageGenerator_' . $type;
+        if (!class_exists($class)) {
+            include dirname(__FILE__) . '/ImageGenerator/' . $type . '.php';
+        }
+        if (class_exists($class)) {
+            $view = new $class($params);
+            // Check that the image object supports what we need for the
+            // requested effect.
+            foreach ($view->need as $need) {
+                if (!Ansel::isAvailable($need)) {
+                    Horde::logMessage($err, 'ERR');
+                    throw new Ansel_Exception(_("This install does not support the %s feature. Please contact your administrator."), $need);
+                }
+            }
+            return $view;
+        } else {
+            Horde::logMessage($err, 'ERR');
+            throw new Ansel_Exception(sprintf(_("Unable to load the definition of %s."), $class));
+        }
+    }
+
+    /**
+     * Utility function to make every effort to find a subgallery that
+     * contains images.
+     *
+     * @param Ansel_Gallery $parent  The gallery to start looking in
+     *
+     * @return Ansel_Gallery  Gallery that has images, or the original $parent
+     */
+    protected function _getGalleryWithImages($parent)
+    {
+        $galleries = $GLOBALS['injector']
+            ->getInstance('Ansel_Storage')
+            ->getScope()
+            ->listGalleries(array('parent' => $parent, 'allLevels' => false));
+
+        foreach ($galleries as $gallery) {
+            if ($gallery->countImages()) {
+                return $gallery;
+            }
+            $result = $this->_getGalleryWithImages($gallery);
+            if ($result->countImages()) {
+                return $result;
+            }
+        }
+
+        return $parent;
+    }
+
+   /**
+     * Utility function to return an array of Horde_Images to use in building a
+    *  polaroid stack. Returns a random set of 5 images from the gallery, or the
+    *  explicitly set default image plus 4 others.
+     *
+     * @return array of Horde_Images
+     */
+    protected function _getStackImages()
+    {
+        $images = array();
+        $gallery = $this->_params['gallery'];
+
+        // Make sure we have images.
+        if (!$gallery->countImages() && $gallery->hasSubGalleries()) {
+            $gallery = $this->_getGalleryWithImages($gallery);
+        }
+
+        $cnt = min(5, $gallery->countImages());
+        $default = $gallery->get('default');
+        if (!empty($default) && $default > 0) {
+            try {
+                $img = $gallery->getImage($default);
+                $img->load('screen');
+                $images[] = $img->getHordeImage();
+                $cnt--;
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
+        }
+
+        for ($i = 0; $i < $cnt; $i++) {
+            $rnd = mt_rand(0, $cnt);
+            try {
+                $temp = $gallery->getImages($rnd, 1);
+                $aimg = array_shift($temp);
+                $aimg->load('screen');
+                $images[] = $aimg->getHordeImage();
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
+        }
+
+        // Reverse the array to ensure the requested default image
+        // is the last in the array (so it will appear on the top of
+        // the stack.
+        return array_reverse($images);
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/Mini.php b/ansel/lib/ImageGenerator/Mini.php
new file mode 100755 (executable)
index 0000000..f00f9d8
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * ImageGenerator to create the mini view.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_Mini extends Ansel_ImageGenerator
+{
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min(50, $this->_dimensions['width']),
+                                      min(50, $this->_dimensions['height']),
+                                      true);
+
+        return $this->_image->getHordeImage();
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/PlainStack.php b/ansel/lib/ImageGenerator/PlainStack.php
new file mode 100644 (file)
index 0000000..509a036
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * ImageGenerator to create the gallery image stacks.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_PlainStack extends Ansel_ImageGenerator
+{
+    public $need = array('PhotoStack');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $imgobjs = $this->_getStackImages();
+        $style = $this->_params['style'];
+        $params = array('width' => 100,
+                        'height' => 100,
+                        'background' => $style['background']);
+
+        $baseImg = Ansel::getImageObject($params);
+        try {
+            $baseImg->addEffect(
+                'PhotoStack',
+                array('images' => $imgobjs,
+                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
+                      'padding' => 0,
+                      'background' => $style['background'],
+                      'type' => 'plain'));
+
+            $baseImg->applyEffects();
+            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
+                             $GLOBALS['conf']['thumbnail']['height']);
+        } catch (Horde_Image_Exception $e) {
+            throw new Ansel_Exception($e);
+        }
+
+        return $baseImg;
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/PolaroidStack.php b/ansel/lib/ImageGenerator/PolaroidStack.php
new file mode 100644 (file)
index 0000000..4befd69
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * ImageGenerator to create the gallery polaroid stacks.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_PolaroidStack extends Ansel_ImageGenerator
+{
+    public $need = array('PhotoStack');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $imgobjs = $this->_getStackImages();
+        $style = $this->_params['style'];
+        $params = array('width' => 100,
+                        'height' => 100,
+                        'background' => $style['background']);
+
+        $baseImg = Ansel::getImageObject($params);
+        try {
+            $baseImg->addEffect(
+                'PhotoStack',
+                array('images' => $imgobjs,
+                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
+                      'padding' => 10,
+                      'background' => $style['background'],
+                      'type' => 'polaroid'));
+            $baseImg->applyEffects();
+            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
+                             $GLOBALS['conf']['thumbnail']['height']);
+
+        } catch (Horde_Image_Exception $e) {
+            throw new Ansel_Exception($e);
+        }
+
+        return $baseImg;
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/PolaroidThumb.php b/ansel/lib/ImageGenerator/PolaroidThumb.php
new file mode 100644 (file)
index 0000000..fc453d1
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/**
+ * ImageGenerator to create the shadowsharpthumb view (sharp corners, shadowed)
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_PolaroidThumb extends Ansel_ImageGenerator
+{
+    public $need = array('PolaroidImage');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+
+        /* Don't bother with these effects for a custom gallery default image
+           (which will have a negative gallery_id). */
+        if ($this->_image->gallery > 0) {
+            if (is_null($this->_style)) {
+                $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($this->_image->gallery);
+                $styleDef = $gal->getStyle();
+            } else {
+                $styleDef = Ansel::getStyleDefinition($this->_style);
+            }
+            try {
+                $this->_image->addEffect('PolaroidImage',
+                                         array('background' => $styleDef['background'],
+                                               'padding' => 5));
+
+                $this->_image->applyEffects();
+            } catch (Horde_Image_Exception $e) {
+                throw new Ansel_Exception($e);
+            }
+
+            return true;
+        }
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/PrettyThumb.php b/ansel/lib/ImageGenerator/PrettyThumb.php
new file mode 100644 (file)
index 0000000..5fe9df5
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * ImageGenerator to create the prettythumb view (rounded, shadowed thumbnails).
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_PrettyThumb extends Ansel_ImageGenerator
+{
+    public $need = array('RoundCorners', 'DropShadow');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+
+        /* Don't bother with these effects for a stack image
+         * (which will have a negative gallery_id). */
+        if ($this->_image->gallery > 0) {
+            if (is_null($this->_style)) {
+                $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($this->_image->gallery);
+                $styleDef = $gal->getStyle();
+            } else {
+                $styleDef = Ansel::getStyleDefinition($this->_style);
+            }
+
+            try {
+                /* Apply the effects - continue on error, but be sure to log */
+                $this->_image->addEffect('RoundCorners', array('border' => 2,
+                                                               'bordercolor' => '#333'));
+
+                $this->_image->addEffect('DropShadow', array('background' => $styleDef['background'],
+                                                             'padding' => 5,
+                                                             'distance' => 5,
+                                                             'fade' => 3));
+            } catch (Horde_Image_Exception $e) {
+                throw new Ansel_Exception($e);
+            }
+            $this->_image->applyEffects();
+
+            return $this->_image->getHordeImage();
+        }
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/RoundedStack.php b/ansel/lib/ImageGenerator/RoundedStack.php
new file mode 100644 (file)
index 0000000..0cdf0ce
--- /dev/null
@@ -0,0 +1,46 @@
+ <?php
+/**
+ * ImageGenerator to create the gallery image stacks.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ *
+ */
+class Ansel_ImageGenerator_RoundedStack extends Ansel_ImageGenerator
+ {
+    public $need = array('PhotoStack');
+
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $imgobjs = $this->_getStackImages();
+        $style = $this->_params['style'];
+        $params = array('width' => 100,
+                        'height' => 100,
+                        'background' => $style['background']);
+
+        $baseImg = Ansel::getImageObject($params);
+
+        try {
+            $baseImg->addEffect(
+                'PhotoStack',
+                array('images' => $imgobjs,
+                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
+                      'padding' => 0,
+                      'background' => $style['background'],
+                      'type' => 'rounded'));
+
+            $baseImg->applyEffects();
+            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
+                             $GLOBALS['conf']['thumbnail']['height']);
+        } catch (Horde_Image_Exception $e) {
+            throw new Ansel_Exception($e);
+        }
+
+        return $baseImg;
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/Screen.php b/ansel/lib/ImageGenerator/Screen.php
new file mode 100755 (executable)
index 0000000..448978a
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * ImageGenerator to create the screen view - image sized for slideshow view.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_Screen extends Ansel_ImageGenerator
+{
+    /**
+     *
+     * @return boolean
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['screen']['height'], $this->_dimensions['height']),
+                              true);
+
+        return $this->_image->getHordeImage();
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/ShadowSharpThumb.php b/ansel/lib/ImageGenerator/ShadowSharpThumb.php
new file mode 100644 (file)
index 0000000..bf9004f
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * ImageGenerator to create the shadowsharpthumb view (sharp corners, shadowed)
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_ShadowSharpThumb extends Ansel_ImageGenerator
+{
+    public $need = array('DropShadow');
+
+    /**
+     *
+     * @return boolean
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+
+        /* Don't bother with these effects for a stack image
+         * (which will have a negative gallery_id). */
+        if ($this->_image->gallery > 0) {
+            if (is_null($this->_style)) {
+                $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($this->_image->gallery);
+                $styleDef = $gal->getStyle();
+            } else {
+                $styleDef = Ansel::getStyleDefinition($this->_style);
+            }
+
+            try {
+                $this->_image->addEffect('Border', array('bordercolor' => '#333', 'borderwidth' => 1));
+                $this->_image->addEffect('DropShadow',
+                                         array('background' => $styleDef['background'],
+                                               'padding' => 5,
+                                               'distance' => 8,
+                                               'fade' => 2));
+                $this->_image->applyEffects();
+            } catch (Horde_Image_Exception $e) {
+                throw new Ansel_Exception($e);
+            }
+
+            return $this->_image->getHordeImage();
+        }
+    }
+
+}
diff --git a/ansel/lib/ImageGenerator/Thumb.php b/ansel/lib/ImageGenerator/Thumb.php
new file mode 100755 (executable)
index 0000000..f6203cd
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+/**
+ * ImageGenerator to create the thumb view (plain, resized thumbnails).
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+class Ansel_ImageGenerator_Thumb extends Ansel_ImageGenerator
+{
+    /**
+     *
+     * @return Horde_Image
+     */
+    protected function _create()
+    {
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
+        return $this->_image->getHordeImage();
+    }
+
+}
diff --git a/ansel/lib/ImageView.php b/ansel/lib/ImageView.php
deleted file mode 100644 (file)
index 5f09eea..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-<?php
-/**
- * Class to abstract the creation of various image views.
- *
- * Copyright 2007-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.
- *
- * Copyright 2007-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
- */
-class Ansel_ImageView
-{
-    /**
-     * Ansel_Image object that this view is created from.
-     *
-     * @var Ansel_Image
-     */
-    protected $_image = null;
-
-    /**
-     * Parameters for this view
-     *
-     * @var array
-     */
-    protected $_params = array();
-
-    /**
-     * Image dimensions
-     *
-     * @var array
-     */
-    protected $_dimensions = array();
-
-    /**
-     * Cache the style information array
-     *
-     * @var array
-     */
-    protected $_style = array();
-
-    /**
-     * Array of required, supported features for this ImageView to work
-     *
-     * @var array
-     */
-    public  $need = array();
-
-    /**
-     * Const'r
-     *
-     * @return Horde_ImageView
-     */
-    public function __construct($params)
-    {
-        $this->_params = $params;
-        if (!empty($params['image'])) {
-            $this->_image = $params['image'];
-        }
-        $this->_style = $params['style'];
-    }
-
-    /**
-     * Create and cache the view.
-     *
-     * @return mixed  Views used as gallery key images return Horde_Image,
-     *                other views return boolean
-     */
-    public function create()
-    {
-        if (!empty($this->_image)) {
-            // Use Horde_Image since we don't know at this point which
-            // view we have loaded.
-            $img = $this->_image->getHordeImage();
-            $this->_dimensions = $img->getDimensions();
-        }
-
-        return $this->_create();
-    }
-
-    /**
-     * Horde_ImageView factory
-     *
-     * @param string $type   The type of concrete instance to return.
-     * @param array $params  Additional parameters needed for the instance.
-     *
-     * @return Ansel_ImageView
-     * @throws Ansel_Exception
-     */
-    function factory($type, $params = array())
-    {
-        $type = basename($type);
-        $class = 'Ansel_ImageView_' . $type;
-        if (!class_exists($class)) {
-            include dirname(__FILE__) . '/ImageView/' . $type . '.php';
-        }
-        if (class_exists($class)) {
-            $view = new $class($params);
-            // Check that the image object supports what we need for the
-            // requested effect.
-            foreach ($view->need as $need) {
-                if (!Ansel::isAvailable($need)) {
-                    Horde::logMessage($err, 'ERR');
-                    throw new Ansel_Exception(_("This install does not support the %s feature. Please contact your administrator."), $need);
-                }
-            }
-            return $view;
-        } else {
-            Horde::logMessage($err, 'ERR');
-            throw new Ansel_Exception(sprintf(_("Unable to load the definition of %s."), $class));
-        }
-    }
-
-    /**
-     * Utility function to make every effort to find a subgallery that
-     * contains images.
-     *
-     * @param Ansel_Gallery $parent  The gallery to start looking in
-     *
-     * @return Ansel_Gallery  Gallery that has images, or the original $parent
-     */
-    protected function _getGalleryWithImages($parent)
-    {
-        $galleries = $GLOBALS['injector']
-            ->getInstance('Ansel_Storage')
-            ->getScope()
-            ->listGalleries(array('parent' => $parent, 'allLevels' => false));
-
-        foreach ($galleries as $gallery) {
-            if ($gallery->countImages()) {
-                return $gallery;
-            }
-            $result = $this->_getGalleryWithImages($gallery);
-            if ($result->countImages()) {
-                return $result;
-            }
-        }
-
-        return $parent;
-    }
-
-   /**
-     * Utility function to return an array of Horde_Images to use in building a
-    *  polaroid stack. Returns a random set of 5 images from the gallery, or the
-    *  explicitly set default image plus 4 others.
-     *
-     * @return array of Horde_Images
-     */
-    protected function _getStackImages()
-    {
-        $images = array();
-        $gallery = $this->_params['gallery'];
-
-        // Make sure we have images.
-        if (!$gallery->countImages() && $gallery->hasSubGalleries()) {
-            $gallery = $this->_getGalleryWithImages($gallery);
-        }
-
-        $cnt = min(5, $gallery->countImages());
-        $default = $gallery->get('default');
-        if (!empty($default) && $default > 0) {
-            try {
-                $img = $gallery->getImage($default);
-                $img->load('screen');
-                $images[] = $img->getHordeImage();
-                $cnt--;
-            } catch (Exception $e) {
-                Horde::logMessage($e, 'ERR');
-            }
-        }
-
-        for ($i = 0; $i < $cnt; $i++) {
-            $rnd = mt_rand(0, $cnt);
-            try {
-                $temp = $gallery->getImages($rnd, 1);
-                $aimg = array_shift($temp);
-                $aimg->load('screen');
-                $images[] = $aimg->getHordeImage();
-            } catch (Exception $e) {
-                Horde::logMessage($e, 'ERR');
-            }
-        }
-
-        // Reverse the array to ensure the requested default image
-        // is the last in the array (so it will appear on the top of
-        // the stack.
-        return array_reverse($images);
-    }
-
-}
diff --git a/ansel/lib/ImageView/Mini.php b/ansel/lib/ImageView/Mini.php
deleted file mode 100755 (executable)
index c09ff57..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
- * ImageView to create the mini view.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_Mini extends Ansel_ImageView
-{
-    /**
-     *
-     * @return Horde_Image
-     */
-    protected function _create()
-    {
-        $this->_image->resize(min(50, $this->_dimensions['width']),
-                                      min(50, $this->_dimensions['height']),
-                                      true);
-
-        return $this->_image->getHordeImage();
-    }
-
-}
diff --git a/ansel/lib/ImageView/PlainStack.php b/ansel/lib/ImageView/PlainStack.php
deleted file mode 100644 (file)
index b251f46..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/**
- * ImageView to create the gallery image stacks.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_PlainStack extends Ansel_ImageView
-{
-    public $need = array('PhotoStack');
-
-    /**
-     *
-     * @return Horde_Image
-     */
-    protected function _create()
-    {
-        $imgobjs = $this->_getStackImages();
-        $style = $this->_params['style'];
-        $params = array('width' => 100,
-                        'height' => 100,
-                        'background' => $style['background']);
-
-        $baseImg = Ansel::getImageObject($params);
-        try {
-            $baseImg->addEffect(
-                'PhotoStack',
-                array('images' => $imgobjs,
-                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
-                      'padding' => 0,
-                      'background' => $style['background'],
-                      'type' => 'plain'));
-
-            $baseImg->applyEffects();
-            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
-                             $GLOBALS['conf']['thumbnail']['height']);
-        } catch (Horde_Image_Exception $e) {
-            throw new Ansel_Exception($e);
-        }
-
-        return $baseImg;
-    }
-
-}
diff --git a/ansel/lib/ImageView/PolaroidStack.php b/ansel/lib/ImageView/PolaroidStack.php
deleted file mode 100644 (file)
index 34e0501..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/**
- * ImageView to create the gallery polaroid stacks.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_PolaroidStack extends Ansel_ImageView
-{
-    public $need = array('PhotoStack');
-
-    /**
-     *
-     * @return Horde_Image
-     */
-    protected function _create()
-    {
-        $imgobjs = $this->_getStackImages();
-        $style = $this->_params['style'];
-        $params = array('width' => 100,
-                        'height' => 100,
-                        'background' => $style['background']);
-
-        $baseImg = Ansel::getImageObject($params);
-        try {
-            $baseImg->addEffect(
-                'PhotoStack',
-                array('images' => $imgobjs,
-                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
-                      'padding' => 10,
-                      'background' => $style['background'],
-                      'type' => 'polaroid'));
-            $baseImg->applyEffects();
-            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
-                             $GLOBALS['conf']['thumbnail']['height']);
-
-        } catch (Horde_Image_Exception $e) {
-            throw new Ansel_Exception($e);
-        }
-
-        return $baseImg;
-    }
-
-}
diff --git a/ansel/lib/ImageView/PolaroidThumb.php b/ansel/lib/ImageView/PolaroidThumb.php
deleted file mode 100644 (file)
index 07486ca..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/**
- * ImageView to create the shadowsharpthumb view (sharp corners, shadowed)
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_PolaroidThumb extends Ansel_ImageView
-{
-    public $need = array('PolaroidImage');
-
-    /**
-     *
-     * @return Horde_Image
-     */
-    protected function _create()
-    {
-        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                              true);
-
-        /* Don't bother with these effects for a custom gallery default image
-           (which will have a negative gallery_id). */
-        if ($this->_image->gallery > 0) {
-            if (is_null($this->_style)) {
-                $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($this->_image->gallery);
-                $styleDef = $gal->getStyle();
-            } else {
-                $styleDef = Ansel::getStyleDefinition($this->_style);
-            }
-            try {
-                $this->_image->addEffect('PolaroidImage',
-                                         array('background' => $styleDef['background'],
-                                               'padding' => 5));
-
-                $this->_image->applyEffects();
-            } catch (Horde_Image_Exception $e) {
-                throw new Ansel_Exception($e);
-            }
-
-            return true;
-        }
-    }
-
-}
diff --git a/ansel/lib/ImageView/PrettyThumb.php b/ansel/lib/ImageView/PrettyThumb.php
deleted file mode 100644 (file)
index 58d2bc1..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * ImageView to create the prettythumb view (rounded, shadowed thumbnails).
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_PrettyThumb extends Ansel_ImageView
-{
-    public $need = array('RoundCorners', 'DropShadow');
-
-    /**
-     *
-     * @return Horde_Image
-     */
-    protected function _create()
-    {
-        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                              true);
-
-        /* Don't bother with these effects for a stack image
-         * (which will have a negative gallery_id). */
-        if ($this->_image->gallery > 0) {
-            if (is_null($this->_style)) {
-                $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($this->_image->gallery);
-                $styleDef = $gal->getStyle();
-            } else {
-                $styleDef = Ansel::getStyleDefinition($this->_style);
-            }
-
-            try {
-                /* Apply the effects - continue on error, but be sure to log */
-                $this->_image->addEffect('RoundCorners', array('border' => 2,
-                                                               'bordercolor' => '#333'));
-
-                $this->_image->addEffect('DropShadow', array('background' => $styleDef['background'],
-                                                             'padding' => 5,
-                                                             'distance' => 5,
-                                                             'fade' => 3));
-            } catch (Horde_Image_Exception $e) {
-                throw new Ansel_Exception($e);
-            }
-            $this->_image->applyEffects();
-
-            return $this->_image->getHordeImage();
-        }
-    }
-
-}
diff --git a/ansel/lib/ImageView/RoundedStack.php b/ansel/lib/ImageView/RoundedStack.php
deleted file mode 100644 (file)
index 76319b9..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
- <?php
-/**
- * ImageView to create the gallery image stacks.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- *
- */
-class Ansel_ImageView_RoundedStack extends Ansel_ImageView
- {
-    public $need = array('PhotoStack');
-
-    /**
-     *
-     * @return Horde_Image
-     */
-    protected function _create()
-    {
-        $imgobjs = $this->_getStackImages();
-        $style = $this->_params['style'];
-        $params = array('width' => 100,
-                        'height' => 100,
-                        'background' => $style['background']);
-
-        $baseImg = Ansel::getImageObject($params);
-
-        try {
-            $baseImg->addEffect(
-                'PhotoStack',
-                array('images' => $imgobjs,
-                      'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
-                      'padding' => 0,
-                      'background' => $style['background'],
-                      'type' => 'rounded'));
-
-            $baseImg->applyEffects();
-            $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
-                             $GLOBALS['conf']['thumbnail']['height']);
-        } catch (Horde_Image_Exception $e) {
-            throw new Ansel_Exception($e);
-        }
-
-        return $baseImg;
-    }
-
-}
diff --git a/ansel/lib/ImageView/Screen.php b/ansel/lib/ImageView/Screen.php
deleted file mode 100755 (executable)
index d50f111..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
- * ImageView to create the screen view - image sized for slideshow view.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_Screen extends Ansel_ImageView
-{
-    /**
-     *
-     * @return boolean
-     */
-    protected function _create()
-    {
-        $this->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']),
-                              min($GLOBALS['conf']['screen']['height'], $this->_dimensions['height']),
-                              true);
-
-        return $this->_image->getHordeImage();
-    }
-
-}
diff --git a/ansel/lib/ImageView/ShadowSharpThumb.php b/ansel/lib/ImageView/ShadowSharpThumb.php
deleted file mode 100644 (file)
index d5b396b..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-/**
- * ImageView to create the shadowsharpthumb view (sharp corners, shadowed)
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_ShadowSharpThumb extends Ansel_ImageView
-{
-    public $need = array('DropShadow');
-
-    /**
-     *
-     * @return boolean
-     */
-    protected function _create()
-    {
-        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                              true);
-
-        /* Don't bother with these effects for a stack image
-         * (which will have a negative gallery_id). */
-        if ($this->_image->gallery > 0) {
-            if (is_null($this->_style)) {
-                $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($this->_image->gallery);
-                $styleDef = $gal->getStyle();
-            } else {
-                $styleDef = Ansel::getStyleDefinition($this->_style);
-            }
-
-            try {
-                $this->_image->addEffect('Border', array('bordercolor' => '#333', 'borderwidth' => 1));
-                $this->_image->addEffect('DropShadow',
-                                         array('background' => $styleDef['background'],
-                                               'padding' => 5,
-                                               'distance' => 8,
-                                               'fade' => 2));
-                $this->_image->applyEffects();
-            } catch (Horde_Image_Exception $e) {
-                throw new Ansel_Exception($e);
-            }
-
-            return $this->_image->getHordeImage();
-        }
-    }
-
-}
diff --git a/ansel/lib/ImageView/Thumb.php b/ansel/lib/ImageView/Thumb.php
deleted file mode 100755 (executable)
index 62f381d..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-/**
- * ImageView to create the thumb view (plain, resized thumbnails).
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Ansel
- */
-class Ansel_ImageView_Thumb extends Ansel_ImageView
-{
-    /**
-     *
-     * @return Horde_Image
-     */
-    protected function _create()
-    {
-        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                              true);
-        return $this->_image->getHordeImage();
-    }
-
-}
index 8b49073..2e56ced 100644 (file)
@@ -221,7 +221,7 @@ abstract class Ansel_View_Base
      *      full   -     Should a full URL be generated? [false]
      *      from   -     Starting image count [0]
      *      count  -     The number of images to include (starting at from) [0]
-     *      image_view - The type of ImageView to obtain the src url for. [screen]
+     *      image_view - The type of ImageGenerator to obtain the src url for. [screen]
      *      view_links - Should the JSON include links to the Image and/or Gallery View? [false]
      *      perpage    - Number of images per page [from user prefs]
      *   </pre>
index d303faa..83cff1f 100644 (file)
@@ -90,7 +90,7 @@ $style = $gallery->getStyle();
 $image_src = Ansel::getImageUrl($image_id, 'full');
 
 echo $galleryurl->link() . Horde::img('galleries.png') . ' ' . _("Back to gallery") . '</a> ';
-echo $imageview_url->link() . Horde::img('galleries.png') . ' ' . _("Cancel") . '</a> ';
+echo $ImageGenerator_url->link() . Horde::img('galleries.png') . ' ' . _("Cancel") . '</a> ';
 
 if (Ansel::isAvailable('rotate')) {
     echo $imageurl->copy()->add('actionID', 'previewrotate270')->link() . Horde::img('image/rotate-270.png') . ' ' . _("Rotate Left") . '</a> ';
index 704037a..138878f 100644 (file)
@@ -6,7 +6,7 @@ $style = $gallery->getStyle();
 $image_src = Ansel::getImageUrl($image_id, 'screen');
 
 echo $galleryurl->link() . Horde::img('galleries.png') . ' ' . _("Back to gallery") . '</a> ';
-echo $imageview_url->link() . Horde::img('galleries.png') . ' ' . _("Cancel") . '</a> ';
+echo $ImageGenerator_url->link() . Horde::img('galleries.png') . ' ' . _("Cancel") . '</a> ';
 
 if (Ansel::isAvailable('rotate')) {
     echo $imageurl->copy()->add('actionID', 'previewrotate270')->link() . Horde::img('image/rotate-270.png') . ' ' . _("Rotate Left") . '</a> ';
index 7e655eb..2ff1d72 100644 (file)
@@ -37,7 +37,7 @@ $style = $gallery->getStyle();
 $image_src = Ansel::getImageUrl($image_id, 'full');
 
 echo $galleryurl->link() . Horde::img('galleries.png') . ' ' . _("Back to gallery") . '</a> ';
-echo $imageview_url->link() . Horde::img('galleries.png') . ' ' . _("Cancel") . '</a> ';
+echo $ImageGenerator_url->link() . Horde::img('galleries.png') . ' ' . _("Cancel") . '</a> ';
 
 if (Ansel::isAvailable('rotate')) {
     echo $imageurl->copy()->add('actionID', 'previewrotate270')->link() . Horde::img('image/rotate-270.png') . ' ' . _("Rotate Left") . '</a> ';