From: Michael J. Rubinsky Date: Wed, 17 Feb 2010 00:04:13 +0000 (-0500) Subject: Some H4 changes, start cleaning up Image object, improve logic, less iteration etc... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=def208a84055817b2715d26e89e4a1abe478d5a6;p=horde.git Some H4 changes, start cleaning up Image object, improve logic, less iteration etc... --- diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index a4af37e8f..a4f0a7300 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -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 diff --git a/ansel/lib/ImageView.php b/ansel/lib/ImageView.php index 7f2149c4f..4cbffc187 100644 --- a/ansel/lib/ImageView.php +++ b/ansel/lib/ImageView.php @@ -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) {} } diff --git a/ansel/lib/ImageView/mini.php b/ansel/lib/ImageView/mini.php index 18e979ccc..8b9f1418a 100755 --- a/ansel/lib/ImageView/mini.php +++ b/ansel/lib/ImageView/mini.php @@ -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); diff --git a/ansel/lib/ImageView/plainstack.php b/ansel/lib/ImageView/plainstack.php index ce1a05b85..ad19bdefd 100644 --- a/ansel/lib/ImageView/plainstack.php +++ b/ansel/lib/ImageView/plainstack.php @@ -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']); diff --git a/ansel/lib/ImageView/polaroidstack.php b/ansel/lib/ImageView/polaroidstack.php index c80330b6a..a712931e1 100644 --- a/ansel/lib/ImageView/polaroidstack.php +++ b/ansel/lib/ImageView/polaroidstack.php @@ -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']); diff --git a/ansel/lib/ImageView/polaroidthumb.php b/ansel/lib/ImageView/polaroidthumb.php index 67e21b240..90fe1199d 100644 --- a/ansel/lib/ImageView/polaroidthumb.php +++ b/ansel/lib/ImageView/polaroidthumb.php @@ -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; } diff --git a/ansel/lib/ImageView/prettythumb.php b/ansel/lib/ImageView/prettythumb.php index 2533b88e5..4c5b86fdb 100644 --- a/ansel/lib/ImageView/prettythumb.php +++ b/ansel/lib/ImageView/prettythumb.php @@ -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; } } diff --git a/ansel/lib/ImageView/roundedstack.php b/ansel/lib/ImageView/roundedstack.php index f8744455f..92a0a617b 100644 --- a/ansel/lib/ImageView/roundedstack.php +++ b/ansel/lib/ImageView/roundedstack.php @@ -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']); diff --git a/ansel/lib/ImageView/screen.php b/ansel/lib/ImageView/screen.php index 00f660951..4d912ed1b 100755 --- a/ansel/lib/ImageView/screen.php +++ b/ansel/lib/ImageView/screen.php @@ -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); diff --git a/ansel/lib/ImageView/shadowsharpthumb.php b/ansel/lib/ImageView/shadowsharpthumb.php index e6b668c27..305788db3 100644 --- a/ansel/lib/ImageView/shadowsharpthumb.php +++ b/ansel/lib/ImageView/shadowsharpthumb.php @@ -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; } diff --git a/ansel/lib/ImageView/thumb.php b/ansel/lib/ImageView/thumb.php index d09a60639..cf769c20d 100755 --- a/ansel/lib/ImageView/thumb.php +++ b/ansel/lib/ImageView/thumb.php @@ -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; }