Track changes to Horde_Image using Exceptions
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 2 Aug 2009 19:53:25 +0000 (15:53 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 2 Aug 2009 19:53:25 +0000 (15:53 -0400)
ansel/faces/search/image.php
ansel/faces/search/image_save.php
ansel/lib/Ansel.php
ansel/lib/ImageView.php
ansel/lib/ImageView/mini.php
ansel/lib/ImageView/polaroidthumb.php
ansel/lib/ImageView/screen.php
ansel/lib/ImageView/shadowsharpthumb.php
ansel/lib/ImageView/thumb.php

index d49f9df..87601f9 100644 (file)
@@ -25,24 +25,25 @@ if ($form->validate()) {
     $driver = empty($conf['image']['convert']) ? 'gd' : 'im';
     $img = Ansel::getImageObject();
     try {
-        $result = $img->loadFile($info['image']['file']);
+        $img->loadFile($info['image']['file']);
+        $dimensions = $img->getDimensions();
     } catch (Horde_Image_Exception $e) {
         $notification->push($e->getMessage());
         header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
         exit;
     }
 
-    $dimensions = $img->getDimensions();
     if ($dimensions['width'] < 50 || $dimensions['height'] < 50) {
         $notification->push(_("Photo is too small. Search photo must be at least 50x50 pixels."));
         header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
         exit;
     }
 
-    $result = $img->resize(min($conf['screen']['width'], $dimensions['width']),
-                            min($conf['screen']['height'], $dimensions['height']));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result->getMessage());
+    try {
+        $img->resize(min($conf['screen']['width'], $dimensions['width']),
+                     min($conf['screen']['height'], $dimensions['height']));
+    } catch (Horde_Image_Exception $e) {
+        $notification->push($e->getMessage());
         header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
         exit;
     }
index dd65fbf..ddd892d 100644 (file)
@@ -43,17 +43,23 @@ try {
 }
 
 /* Crop image. */
-$result = $img->crop($x1, $y1, $x2, $y2);
-if (is_a($result, 'PEAR_Error')) {
-    $notification->push($result->getMessage());
+try {
+    $result = $img->crop($x1, $y1, $x2, $y2);
+} catch (Horde_Image_Exception $e) {
+    $notification->push($e->getMessage());
     header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
     exit;
 }
 
 /* Resize image. */
-$img->getDimensions();
-if ($img->_width >= 50) {
-    $img->resize(min(50, $img->_width), min(50, $img->_height), true);
+try {
+    $img->getDimensions();
+    if ($img->_width >= 50) {
+        $img->resize(min(50, $img->_width), min(50, $img->_height), true);
+    }
+} catch (Horde_Image_Exception $e) {
+    $notification->push($e->getMessage());
+    header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
 }
 
 /* Save image. */
index 48831f5..90513a0 100644 (file)
@@ -522,6 +522,7 @@ class Ansel {
         $params = array_merge(array('type' => $conf['image']['type'],
                                     'context' => $context),
                               $params);
+        //@TODO: get around to updating horde/config/conf.xml to include the imagick driver
         $driver = empty($conf['image']['convert']) ? 'Gd' : 'Im';
         return Horde_Image::factory($driver, $params);
     }
@@ -2281,10 +2282,7 @@ class Ansel_Image {
             Horde::logMessage($data, __FILE__, __LINE__, PEAR_LOG_ERR);
             return $data;
         }
-
-        if (is_a($result = $this->_image->loadString($this->getVFSPath('full') . '/' . $this->id, $data), 'PEAR_Error')) {
-            return $result;
-        }
+        $this->_image->loadString($this->getVFSPath('full') . '/' . $this->id, $data);
         $styleDef = Ansel::getStyleDefinition($style);
         if ($view == 'prettythumb') {
             $viewType = $styleDef['thumbstyle'];
@@ -2557,36 +2555,35 @@ class Ansel_Image {
         /* Flag to determine if we need to resave the image data */
         $needUpdate = false;
 
-        /* Populate any local properties that come from EXIF */
-        if (!is_a($exif_fields, 'PEAR_Error')) {
-            /* Save any geo data to a seperate table as well */
-            if (!empty($exif_fields['GPSLatitude'])) {
-                $this->lat = $exif_fields['GPSLatitude'];
-                $this->lng = $exif_fields['GPSLongitude'];
-                $this->geotag_timestamp = time();
-                $needUpdate = true;
-            }
+        /* Populate any local properties that come from EXIF
+         * Save any geo data to a seperate table as well */
+        if (!empty($exif_fields['GPSLatitude'])) {
+            $this->lat = $exif_fields['GPSLatitude'];
+            $this->lng = $exif_fields['GPSLongitude'];
+            $this->geotag_timestamp = time();
+            $needUpdate = true;
+        }
 
-            if (!empty($exif_fields['DateTimeOriginal'])) {
-                $this->originalDate = $exif_fields['DateTimeOriginal'];
-                $needUpdate = true;
-            }
+        if (!empty($exif_fields['DateTimeOriginal'])) {
+            $this->originalDate = $exif_fields['DateTimeOriginal'];
+            $needUpdate = true;
+        }
 
-            /* Attempt to autorotate based on Orientation field */
-            $this->_autoRotate();
+        /* Attempt to autorotate based on Orientation field */
+        $this->_autoRotate();
 
-            /* Save attributes. */
-            $insert = $GLOBALS['ansel_db']->prepare('INSERT INTO ansel_image_attributes (image_id, attr_name, attr_value) VALUES (?, ?, ?)');
-            foreach ($exif_fields as $name => $value) {
-                $result = $insert->execute(array($this->id, $name, Horde_String::convertCharset($value, Horde_Nls::getCharset(), $GLOBALS['conf']['sql']['charset'])));
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
-                }
-                /* Cache it locally */
-                $this->_exif[$name] = Horde_Image_Exif::getHumanReadable($name, $value);
+        /* Save attributes. */
+        $insert = $GLOBALS['ansel_db']->prepare('INSERT INTO ansel_image_attributes (image_id, attr_name, attr_value) VALUES (?, ?, ?)');
+        foreach ($exif_fields as $name => $value) {
+            $result = $insert->execute(array($this->id, $name, Horde_String::convertCharset($value, Horde_Nls::getCharset(), $GLOBALS['conf']['sql']['charset'])));
+            if (is_a($result, 'PEAR_Error')) {
+                return $result;
             }
-            $insert->free();
+            /* Cache it locally */
+            $this->_exif[$name] = Horde_Image_Exif::getHumanReadable($name, $value);
         }
+        $insert->free();
+
 
         return $needUpdate;
     }
@@ -2762,7 +2759,7 @@ class Ansel_Image {
             return $result;
         }
 
-        return $this->_image->display();
+        $this->_image->display();
     }
 
     /**
@@ -2801,13 +2798,13 @@ class Ansel_Image {
     {
         $this->load($view);
         $this->_dirty = true;
-        return $this->_image->rotate($angle);
+        $this->_image->rotate($angle);
     }
 
     function crop($x1, $y1, $x2, $y2)
     {
         $this->_dirty = true;
-        return $this->_image->crop($x1, $y1, $x2, $y2);
+        $this->_image->crop($x1, $y1, $x2, $y2);
     }
 
     /**
@@ -2819,7 +2816,7 @@ class Ansel_Image {
     {
         $this->load($view);
         $this->_dirty = true;
-        return $this->_image->grayscale();
+        $this->_image->grayscale();
     }
 
     /**
@@ -2867,8 +2864,6 @@ class Ansel_Image {
             $params['font'] = $GLOBALS['conf']['image']['font'];
         }
         $this->_image->addEffect('TextWatermark', $params);
-
-        return true;
     }
 
     /**
@@ -2880,7 +2875,7 @@ class Ansel_Image {
     {
         $this->load($view);
         $this->_dirty = true;
-        return $this->_image->flip();
+        $this->_image->flip();
     }
 
     /**
@@ -2892,7 +2887,7 @@ class Ansel_Image {
     {
         $this->load($view);
         $this->_dirty = true;
-        return $this->_image->mirror();
+        $this->_image->mirror();
     }
 
     /**
index 55d2902..6e9b966 100644 (file)
@@ -61,10 +61,6 @@ class Ansel_ImageView {
     {
         if (!empty($this->_image)) {
             $this->_dimensions = $this->_image->_image->getDimensions();
-            if (is_a($this->_dimensions, 'PEAR_Error')) {
-                Horde::logMessage($this->_dimensions, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return $this->_dimensions;
-            }
         }
         return $this->_create();
     }
index 7056587..18e979c 100755 (executable)
@@ -9,9 +9,11 @@ class Ansel_ImageView_mini extends Ansel_ImageView {
 
     function _create()
     {
-        return $this->_image->_image->resize(min(50, $this->_dimensions['width']),
-                                             min(50, $this->_dimensions['height']),
-                                             true);
+        $this->_image->_image->resize(min(50, $this->_dimensions['width']),
+                                      min(50, $this->_dimensions['height']),
+                                      true);
+
+        return true;
     }
 
 }
index 7d4572e..5d4950d 100644 (file)
@@ -25,14 +25,13 @@ class Ansel_ImageView_polaroidthumb extends Ansel_ImageView {
             } else {
                 $styleDef = Ansel::getStyleDefinition($this->_style);
             }
-            $res = $this->_image->_image->addEffect('PolaroidImage',
-                                                    array('background' => $styleDef['background'],
-                                                          'padding' => 5));
-            if (is_a($res, 'PEAR_Error')) {
-                Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
+            $this->_image->_image->addEffect('PolaroidImage',
+                                              array('background' => $styleDef['background'],
+                                                    'padding' => 5));
+
+            $this->_image->_image->applyEffects();
 
-            return $this->_image->_image->applyEffects();
+            return true;
         }
     }
 
index 255cf82..00f6609 100755 (executable)
@@ -9,9 +9,11 @@ class Ansel_ImageView_screen extends Ansel_ImageView {
 
     function _create()
     {
-        return $this->_image->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']),
-                                             min($GLOBALS['conf']['screen']['height'], $this->_dimensions['height']),
-                                             true);
+        $this->_image->_image->resize(min($GLOBALS['conf']['screen']['width'], $this->_dimensions['width']),
+                                      min($GLOBALS['conf']['screen']['height'], $this->_dimensions['height']),
+                                      true);
+
+        return true;
     }
 
 }
index 1b77699..f68e52b 100644 (file)
@@ -28,17 +28,15 @@ class Ansel_ImageView_shadowsharpthumb extends Ansel_ImageView {
             $res = $this->_image->_image->addEffect(
                 'border', array('bordercolor' => '#333'));
 
-            $res = $this->_image->_image->addEffect('DropShadow',
-                                                    array('background' => $styleDef['background'],
-                                                          'padding' => 5,
-                                                          'distance' => '8',
-                                                          'fade' => 2));
-
-            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' => '8',
+                                                   'fade' => 2));
+
+            $this->_image->_image->applyEffects();
 
-            return $this->_image->_image->applyEffects();
+            return true;
         }
     }
 
index 8865df0..d09a606 100755 (executable)
@@ -9,9 +9,11 @@ class Ansel_ImageView_thumb extends Ansel_ImageView {
 
     function _create()
     {
-        return $this->_image->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
-                                             min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
-                                             true);
+        $this->_image->_image->resize(min($GLOBALS['conf']['thumbnail']['width'], $this->_dimensions['width']),
+                                      min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
+                                      true);
+
+        return true;
     }
 
 }