Catch errors from Horde_Image
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Aug 2009 21:00:44 +0000 (17:00 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Aug 2009 21:44:46 +0000 (17:44 -0400)
ansel/lib/ImageView.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/shadowsharpthumb.php

index 6e9b966..34f0474 100644 (file)
@@ -62,6 +62,7 @@ class Ansel_ImageView {
         if (!empty($this->_image)) {
             $this->_dimensions = $this->_image->_image->getDimensions();
         }
+
         return $this->_create();
     }
 
index b4bbf10..ab26198 100644 (file)
@@ -27,22 +27,22 @@ class Ansel_ImageView_plainstack extends Ansel_ImageView {
                         'background' => $style['background']);
 
         $baseImg = Ansel::getImageObject($params);
-        $result = $baseImg->addEffect(
-            'PhotoStack',
-            array('images' => $imgobjs,
-                  'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
-                  'padding' => 0,
-                  'background' => $style['background'],
-                  'type' => 'plain'));
-
-        $baseImg->applyEffects();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
+        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) {
+            return false;
         }
 
-        $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
-                         $GLOBALS['conf']['thumbnail']['height']);
-
         return $baseImg;
 
     }
index 4c0d251..697f66e 100644 (file)
@@ -27,22 +27,22 @@ class Ansel_ImageView_polaroidstack extends Ansel_ImageView {
                         'background' => $style['background']);
 
         $baseImg = Ansel::getImageObject($params);
-        $result = $baseImg->addEffect(
-            'PhotoStack',
-            array('images' => $imgobjs,
-                  'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
-                  'padding' => 10,
-                  'background' => $style['background'],
-                  'type' => 'polaroid'));
-
-        $baseImg->applyEffects();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
+        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) {
+            return false;
         }
 
-        $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
-                         $GLOBALS['conf']['thumbnail']['height']);
-
         return $baseImg;
 
     }
index 5d4950d..67e21b2 100644 (file)
@@ -25,11 +25,15 @@ class Ansel_ImageView_polaroidthumb extends Ansel_ImageView {
             } else {
                 $styleDef = Ansel::getStyleDefinition($this->_style);
             }
-            $this->_image->_image->addEffect('PolaroidImage',
-                                              array('background' => $styleDef['background'],
-                                                    'padding' => 5));
+            try {
+                $this->_image->_image->addEffect('PolaroidImage',
+                                                  array('background' => $styleDef['background'],
+                                                        'padding' => 5));
 
-            $this->_image->_image->applyEffects();
+                $this->_image->_image->applyEffects();
+            } catch (Horde_Image_Exception $e) {
+                return false;
+            }
 
             return true;
         }
index 7f3cf7e..2533b88 100644 (file)
@@ -25,21 +25,17 @@ class Ansel_ImageView_prettythumb extends Ansel_ImageView {
                 $styleDef = Ansel::getStyleDefinition($this->_style);
             }
 
-            /* Apply the effects - continue on error, but be sure to log */
-            $res = $this->_image->_image->addEffect('RoundCorners',
-                                                    array('border' => 2,
-                                                          'bordercolor' => '#333'));
-            if (is_a($res, 'PEAR_Error')) {
-                Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
+            try {
+                /* Apply the effects - continue on error, but be sure to log */
+                $this->_image->_image->addEffect('RoundCorners', array('border' => 2,
+                                                                       'bordercolor' => '#333'));
 
-            $res = $this->_image->_image->addEffect('DropShadow',
-                                                    array('background' => $styleDef['background'],
-                                                          'padding' => 5,
-                                                          'distance' => 5,
-                                                          'fade' => 3));
-            if (is_a($res, 'PEAR_Error')) {
-                Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
+                $this->_image->_image->addEffect('DropShadow', array('background' => $styleDef['background'],
+                                                                     'padding' => 5,
+                                                                     'distance' => 5,
+                                                                     'fade' => 3));
+            } catch (Horde_Image_Exception $e) {
+                return false;
             }
 
             return $this->_image->_image->applyEffects();
index 2a64672..a646c30 100644 (file)
@@ -28,21 +28,22 @@ class Ansel_ImageView_roundedstack extends Ansel_ImageView {
                         'background' => $style['background']);
 
         $baseImg = Ansel::getImageObject($params);
-        $result = $baseImg->addEffect(
-            'PhotoStack',
-            array('images' => $imgobjs,
-                  'resize_height' => $GLOBALS['conf']['thumbnail']['height'],
-                  'padding' => 0,
-                  'background' => $style['background'],
-                  'type' => 'rounded'));
-
-        $baseImg->applyEffects();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
-        $baseImg->resize($GLOBALS['conf']['thumbnail']['width'],
-                         $GLOBALS['conf']['thumbnail']['height']);
+        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) {
+            return false;
+        }
 
         return $baseImg;
 
index f68e52b..e6b668c 100644 (file)
@@ -25,16 +25,17 @@ class Ansel_ImageView_shadowsharpthumb extends Ansel_ImageView {
                 $styleDef = Ansel::getStyleDefinition($this->_style);
             }
 
-            $res = $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();
+            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();
+            } catch (Horde_Image_Exception $e) {
+                return false;
+            }
 
             return true;
         }