Exceptions from Horde_Image::loadFile
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 2 Aug 2009 16:41:41 +0000 (12:41 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 2 Aug 2009 16:41:41 +0000 (12:41 -0400)
ansel/faces/search/image.php
ansel/faces/search/image_save.php
folks/lib/Driver.php
framework/Image/lib/Horde/Image/Base.php
framework/Image/lib/Horde/Image/Gd.php

index 9cfe651..d49f9df 100644 (file)
@@ -24,9 +24,10 @@ if ($form->validate()) {
     $tmp = Horde::getTempDir();
     $driver = empty($conf['image']['convert']) ? 'gd' : 'im';
     $img = Ansel::getImageObject();
-    $result = $img->loadFile($info['image']['file']);
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result->getMessage());
+    try {
+        $result = $img->loadFile($info['image']['file']);
+    } catch (Horde_Image_Exception $e) {
+        $notification->push($e->getMessage());
         header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
         exit;
     }
index c34e4f1..dd65fbf 100644 (file)
@@ -34,9 +34,10 @@ if ($x2 - $x1 < 50 || $y2 - $y1 < 50) {
 /* Create Horde_Image driver. */
 $img = Ansel::getImageObject();
 $driver = empty($conf['image']['convert']) ? 'Gd' : 'Im';
-$result = $img->loadFile($path);
-if (is_a($result, 'PEAR_Error')) {
-    $notification->push($result->getMessage());
+try {
+    $result = $img->loadFile($path);
+} catch (Horde_Image_Exception $e) {
+    $notification->push($e->getMessage());
     header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
     exit;
 }
index cb9f0fb..6238795 100644 (file)
@@ -98,12 +98,11 @@ class Folks_Driver {
         $img = Horde_Image::factory($driver,
                                     array('type' => $conf['images']['image_type'],
                                           'context' => $context));
-
-        $result = $img->loadFile($file);
-        if ($result instanceof PEAR_Error) {
-            return $result;
+        try {
+            $result = $img->loadFile($file);
+        } catch (Horde_Image_Exception $e) {
+            throw new Horde_Exception($e);
         }
-
         $dimensions = $img->getDimensions();
         if ($dimensions instanceof PEAR_Error) {
             return $dimensions;
index fc31e55..08c84d8 100644 (file)
@@ -103,10 +103,11 @@ class Horde_Image_Base
      */
     protected function __construct($params, $context = array())
     {
-        //@TODO: This is a temporary BC hack until I update all new Horde_Image calls
+
         if (empty($context['tmpdir'])) {
             throw new InvalidArgumentException('A path to a temporary directory is required.');
         }
+
         $this->_tmpdir = $context['tmpdir'];
         if (isset($params['width'])) {
             $this->_width = $params['width'];
@@ -215,27 +216,6 @@ class Horde_Image_Base
     }
 
     /**
-     * Add an observer to this image. The observer will be notified
-     * when the image's changes.
-     */
-    public function addObserver($method, $object)
-    {
-        $this->_observers[] = array($method, $object);
-    }
-
-    /**
-     * Let observers know that something happened worth acting on.
-     */
-    public function notifyObservers()
-    {
-        for ($i = 0; $i < count($this->_observers); ++$i) {
-            $obj = $this->_observers[$i][1];
-            $method = $this->_observers[$i][0];
-            $obj->$method($this);
-        }
-    }
-
-    /**
      * Reset the image data to defaults.
      */
     public function reset()
@@ -292,18 +272,19 @@ class Horde_Image_Base
      *
      * @return mixed  True if successful or already loaded, PEAR Error if file
      *                does not exist or could not be loaded.
+     * @throws Horde_Image_Exception
      */
     public function loadFile($filename)
     {
         if ($filename != $this->_id) {
             $this->reset();
             if (!file_exists($filename)) {
-                return PEAR::raiseError('The image file ' . $filename . ' does not exist.');
+                throw new Horde_Image_Exception(sprintf("The image file, %s, does not exist.", $filename));
             }
             if ($this->_data = file_get_contents($filename)) {
                 $this->_id = $filename;
             } else {
-                return PEAR::raiseError('Could not load the image file ' . $filename);
+                throw new Horde_Image_Exception(sprintf("Could not load the image file %s", $filename));
             }
         }
 
@@ -365,9 +346,6 @@ class Horde_Image_Base
     {
         $class = str_replace('Horde_Image_', '', get_class($this));
         $effect = Horde_Image_Effect::factory($type, $class, $params);
-        if (is_a($effect, 'PEAR_Error')) {
-            return $effect;
-        }
         $effect->setImageObject($this);
         return $effect->apply();
     }
index a1f3b38..b2117da 100644 (file)
@@ -210,14 +210,7 @@ class Horde_Image_Gd extends Horde_Image_Base
      */
     public function loadFile($filename)
     {
-        if (is_a($result = $this->reset(), 'PEAR_Error')) {
-            return $result;
-        }
-
-        if (is_a($info = $this->call('getimagesize', array($filename)), 'PEAR_Error')) {
-            return $info;
-        }
-
+        $info = $this->call('getimagesize', array($filename));
         if (is_array($info)) {
             switch ($info[2]) {
             case 1:
@@ -242,18 +235,11 @@ class Horde_Image_Gd extends Horde_Image_Base
             }
         }
 
-        if (is_a($this->_im, 'PEAR_Error')) {
-            return $this->_im;
-        }
-
         if (is_resource($this->_im)) {
             return true;
         }
 
         $result = parent::loadFile($filename);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         return $this->_im = $this->call('imageCreateFromString', array($this->_data));
     }