From d9e1fae251387182656cc3f354b11046aa67e751 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sun, 2 Aug 2009 15:53:25 -0400 Subject: [PATCH] Track changes to Horde_Image using Exceptions --- ansel/faces/search/image.php | 13 +++--- ansel/faces/search/image_save.php | 18 ++++++--- ansel/lib/Ansel.php | 69 +++++++++++++++----------------- ansel/lib/ImageView.php | 4 -- ansel/lib/ImageView/mini.php | 8 ++-- ansel/lib/ImageView/polaroidthumb.php | 13 +++--- ansel/lib/ImageView/screen.php | 8 ++-- ansel/lib/ImageView/shadowsharpthumb.php | 18 ++++----- ansel/lib/ImageView/thumb.php | 8 ++-- 9 files changed, 80 insertions(+), 79 deletions(-) diff --git a/ansel/faces/search/image.php b/ansel/faces/search/image.php index d49f9df6d..87601f93e 100644 --- a/ansel/faces/search/image.php +++ b/ansel/faces/search/image.php @@ -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; } diff --git a/ansel/faces/search/image_save.php b/ansel/faces/search/image_save.php index dd65fbfd4..ddd892d7f 100644 --- a/ansel/faces/search/image_save.php +++ b/ansel/faces/search/image_save.php @@ -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. */ diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index 48831f52e..90513a0a4 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -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(); } /** diff --git a/ansel/lib/ImageView.php b/ansel/lib/ImageView.php index 55d2902d7..6e9b96694 100644 --- a/ansel/lib/ImageView.php +++ b/ansel/lib/ImageView.php @@ -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(); } diff --git a/ansel/lib/ImageView/mini.php b/ansel/lib/ImageView/mini.php index 705658772..18e979ccc 100755 --- a/ansel/lib/ImageView/mini.php +++ b/ansel/lib/ImageView/mini.php @@ -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; } } diff --git a/ansel/lib/ImageView/polaroidthumb.php b/ansel/lib/ImageView/polaroidthumb.php index 7d4572e8a..5d4950d4d 100644 --- a/ansel/lib/ImageView/polaroidthumb.php +++ b/ansel/lib/ImageView/polaroidthumb.php @@ -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; } } diff --git a/ansel/lib/ImageView/screen.php b/ansel/lib/ImageView/screen.php index 255cf823c..00f660951 100755 --- a/ansel/lib/ImageView/screen.php +++ b/ansel/lib/ImageView/screen.php @@ -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; } } diff --git a/ansel/lib/ImageView/shadowsharpthumb.php b/ansel/lib/ImageView/shadowsharpthumb.php index 1b77699d7..f68e52b3e 100644 --- a/ansel/lib/ImageView/shadowsharpthumb.php +++ b/ansel/lib/ImageView/shadowsharpthumb.php @@ -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; } } diff --git a/ansel/lib/ImageView/thumb.php b/ansel/lib/ImageView/thumb.php index 8865df0d2..d09a60639 100755 --- a/ansel/lib/ImageView/thumb.php +++ b/ansel/lib/ImageView/thumb.php @@ -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; } } -- 2.11.0