Some H4 changes, start cleaning up Image object, improve logic, less iteration etc...
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 17 Feb 2010 00:04:13 +0000 (19:04 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 17 Feb 2010 00:59:39 +0000 (19:59 -0500)
ansel/lib/Image.php
ansel/lib/ImageView.php
ansel/lib/ImageView/mini.php
ansel/lib/ImageView/plainstack.php
ansel/lib/ImageView/polaroidstack.php
ansel/lib/ImageView/polaroidthumb.php
ansel/lib/ImageView/prettythumb.php
ansel/lib/ImageView/roundedstack.php
ansel/lib/ImageView/screen.php
ansel/lib/ImageView/shadowsharpthumb.php
ansel/lib/ImageView/thumb.php

index a4af37e..a4f0a73 100644 (file)
@@ -21,7 +21,7 @@ class Ansel_Image Implements Iterator
     /**
      * @var Horde_Image_Base  Horde_Image object for this image.
      */
-    public $_image;
+    protected $_image;
     protected $_dirty;
     protected $_loaded = array();
     protected $_data = array();
@@ -136,6 +136,16 @@ class Ansel_Image Implements Iterator
     }
 
     /**
+     * Obtain a reference to the underlying Horde_Image
+     *
+     * @return Horde_Image_Base
+     */
+    public function &getHordeImage()
+    {
+        return $this->_image;
+    }
+
+    /**
      * Return the vfs path for this image.
      *
      * @param string $view   The view we want.
@@ -848,6 +858,21 @@ class Ansel_Image Implements Iterator
     }
 
     /**
+     * Resize the current image. This operation takes place immediately.
+     *
+     * @param integer $width        The new width.
+     * @param integer $height       The new height.
+     * @param boolean $ratio        Maintain original aspect ratio.
+     * @param boolean $keepProfile  Keep the image meta data.
+     *
+     * @return void
+     */
+    public function resize($width, $height, $ratio = true, $keepProfile = false)
+    {
+        $this->_image->resize($width, $height, $ratio, $keepProfile);
+    }
+
+    /**
      * Converts the image to grayscale.
      *
      * @param string $view The view (size) to work with.
@@ -930,6 +955,29 @@ class Ansel_Image Implements Iterator
     }
 
     /**
+     * Add an effect to the effect stack
+     *
+     * @param string $type    The effect to add.
+     * @param array  $params  The effect parameters.
+     *
+     * @return mixed
+     */
+    function addEffect($type, $params = array())
+    {
+        return $this->_image->addEffect($type, $params);
+    }
+
+    /**
+     * Apply any pending effects to the underlaying Horde_Image
+     *
+     * @return void
+     */
+    public function applyEffects()
+    {
+        $this->_image->applyEffects();
+    }
+
+    /**
      * Returns this image's tags.
      *
      * @return mixed  An array of tags | PEAR_Error
index 7f2149c..4cbffc1 100644 (file)
@@ -60,7 +60,10 @@ class Ansel_ImageView {
     function create()
     {
         if (!empty($this->_image)) {
-            $this->_dimensions = $this->_image->_image->getDimensions();
+            // 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();
@@ -132,6 +135,8 @@ class Ansel_ImageView {
      * Utility function to return an array of Ansel_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
      */
     function _getStackImages()
     {
@@ -147,8 +152,9 @@ class Ansel_ImageView {
         $default = $gallery->get('default');
         if (!empty($default) && $default > 0) {
             try {
-                $img = &$gallery->getImage($default);
-                $images[] = &$gallery->getImage($default);
+                $img = $gallery->getImage($default);
+                $img->load('screen');
+                $images[] = $img->getHordeImage();//&$gallery->getImage($default);
                 $cnt--;
             } catch (Horde_Exception $e) {}
         }
@@ -157,7 +163,9 @@ class Ansel_ImageView {
             $rnd = mt_rand(0, $cnt);
             try {
                 $temp = $gallery->getImages($rnd, 1);
-                 $images[] = array_shift($temp);
+                $aimg = array_shift($temp);
+                $aimg->load('screen');
+                $images[] = $aimg->getHordeImage();
             } catch (Horde_Exception $e) {}
         }
 
index 18e979c..8b9f141 100755 (executable)
@@ -9,7 +9,7 @@ class Ansel_ImageView_mini extends Ansel_ImageView {
 
     function _create()
     {
-        $this->_image->_image->resize(min(50, $this->_dimensions['width']),
+        $this->_image->resize(min(50, $this->_dimensions['width']),
                                       min(50, $this->_dimensions['height']),
                                       true);
 
index ce1a05b..ad19bde 100644 (file)
@@ -11,14 +11,8 @@ class Ansel_ImageView_plainstack extends Ansel_ImageView {
 
     function _create()
     {
-        $imgobjs = array();
-        $images = $this->_getStackImages();
+        $imgobjs = $this->_getStackImages();
         $style = $this->_params['style'];
-        foreach ($images as $image) {
-            $result = $image->load('screen');
-            $imgobjs[] = $image->_image;
-        }
-
         $params = array('width' => 100,
                         'height' => 100,
                         'background' => $style['background']);
index c80330b..a712931 100644 (file)
@@ -11,14 +11,8 @@ class Ansel_ImageView_polaroidstack extends Ansel_ImageView {
 
     function _create()
     {
-        $imgobjs = array();
-        $images = $this->_getStackImages();
+        $imgobjs = $this->_getStackImages();
         $style = $this->_params['style'];
-        foreach ($images as $image) {
-            $image->load('screen');
-            $imgobjs[] = $image->_image;
-        }
-
         $params = array('width' => 100,
                         'height' => 100,
                         'background' => $style['background']);
index 67e21b2..90fe119 100644 (file)
@@ -12,9 +12,9 @@ class Ansel_ImageView_polaroidthumb extends Ansel_ImageView {
 
     function _create()
     {
-        $this->_image->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                                      min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                                      true);
+        $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). */
@@ -26,11 +26,11 @@ class Ansel_ImageView_polaroidthumb extends Ansel_ImageView {
                 $styleDef = Ansel::getStyleDefinition($this->_style);
             }
             try {
-                $this->_image->_image->addEffect('PolaroidImage',
-                                                  array('background' => $styleDef['background'],
-                                                        'padding' => 5));
+                $this->_image->addEffect('PolaroidImage',
+                                         array('background' => $styleDef['background'],
+                                               'padding' => 5));
 
-                $this->_image->_image->applyEffects();
+                $this->_image->applyEffects();
             } catch (Horde_Image_Exception $e) {
                 return false;
             }
index 2533b88..4c5b86f 100644 (file)
@@ -11,9 +11,9 @@ class Ansel_ImageView_prettythumb extends Ansel_ImageView {
 
     function _create()
     {
-        $this->_image->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                                      min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                                      true);
+        $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). */
@@ -27,18 +27,19 @@ class Ansel_ImageView_prettythumb extends Ansel_ImageView {
 
             try {
                 /* Apply the effects - continue on error, but be sure to log */
-                $this->_image->_image->addEffect('RoundCorners', array('border' => 2,
-                                                                       'bordercolor' => '#333'));
+                $this->_image->addEffect('RoundCorners', array('border' => 2,
+                                                               'bordercolor' => '#333'));
 
-                $this->_image->_image->addEffect('DropShadow', array('background' => $styleDef['background'],
-                                                                     'padding' => 5,
-                                                                     'distance' => 5,
-                                                                     'fade' => 3));
+                $this->_image->addEffect('DropShadow', array('background' => $styleDef['background'],
+                                                             'padding' => 5,
+                                                             'distance' => 5,
+                                                             'fade' => 3));
             } catch (Horde_Image_Exception $e) {
                 return false;
             }
+            $this->_image->applyEffects();
 
-            return $this->_image->_image->applyEffects();
+            return true;
         }
     }
 
index f874445..92a0a61 100644 (file)
@@ -12,14 +12,8 @@ class Ansel_ImageView_roundedstack extends Ansel_ImageView {
 
     function _create()
     {
-        $imgobjs = array();
-        $images = $this->_getStackImages();
+        $imgobjs = $this->_getStackImages();
         $style = $this->_params['style'];
-        foreach ($images as $image) {
-            $result = $image->load('screen');
-            $imgobjs[] = $image->_image;
-        }
-
         $params = array('width' => 100,
                         'height' => 100,
                         'background' => $style['background']);
index 00f6609..4d912ed 100755 (executable)
@@ -9,7 +9,7 @@ class Ansel_ImageView_screen extends Ansel_ImageView {
 
     function _create()
     {
-        $this->_image->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']),
+        $this->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']),
                                       min($GLOBALS['conf']['screen']['height'], $this->_dimensions['height']),
                                       true);
 
index e6b668c..305788d 100644 (file)
@@ -11,9 +11,9 @@ class Ansel_ImageView_shadowsharpthumb extends Ansel_ImageView {
 
     function _create()
     {
-        $this->_image->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                                      min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                                      true);
+        $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). */
@@ -26,13 +26,13 @@ class Ansel_ImageView_shadowsharpthumb extends Ansel_ImageView {
             }
 
             try {
-                $this->_image->_image->addEffect('border', array('bordercolor' => '#333'));
-                $this->_image->_image->addEffect('DropShadow',
-                                                 array('background' => $styleDef['background'],
-                                                       'padding' => 5,
-                                                       'distance' => '8',
-                                                       'fade' => 2));
-                $this->_image->_image->applyEffects();
+                $this->_image->addEffect('border', array('bordercolor' => '#333'));
+                $this->_image->addEffect('DropShadow',
+                                         array('background' => $styleDef['background'],
+                                               'padding' => 5,
+                                               'distance' => '8',
+                                               'fade' => 2));
+                $this->_image->applyEffects();
             } catch (Horde_Image_Exception $e) {
                 return false;
             }
index d09a606..cf769c2 100755 (executable)
@@ -9,10 +9,9 @@ class Ansel_ImageView_thumb extends Ansel_ImageView {
 
     function _create()
     {
-        $this->_image->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                                      min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                                      true);
-
+        $this->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                              min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                              true);
         return true;
     }