From: Michael J. Rubinsky Date: Sun, 2 Aug 2009 16:41:41 +0000 (-0400) Subject: Exceptions from Horde_Image::loadFile X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=083a5d8dfac03022093c07fad5ffca6afa012aa8;p=horde.git Exceptions from Horde_Image::loadFile --- diff --git a/ansel/faces/search/image.php b/ansel/faces/search/image.php index 9cfe65115..d49f9df6d 100644 --- a/ansel/faces/search/image.php +++ b/ansel/faces/search/image.php @@ -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; } diff --git a/ansel/faces/search/image_save.php b/ansel/faces/search/image_save.php index c34e4f16c..dd65fbfd4 100644 --- a/ansel/faces/search/image_save.php +++ b/ansel/faces/search/image_save.php @@ -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; } diff --git a/folks/lib/Driver.php b/folks/lib/Driver.php index cb9f0fb30..6238795f0 100644 --- a/folks/lib/Driver.php +++ b/folks/lib/Driver.php @@ -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; diff --git a/framework/Image/lib/Horde/Image/Base.php b/framework/Image/lib/Horde/Image/Base.php index fc31e551d..08c84d803 100644 --- a/framework/Image/lib/Horde/Image/Base.php +++ b/framework/Image/lib/Horde/Image/Base.php @@ -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(); } diff --git a/framework/Image/lib/Horde/Image/Gd.php b/framework/Image/lib/Horde/Image/Gd.php index a1f3b3888..b2117dafc 100644 --- a/framework/Image/lib/Horde/Image/Gd.php +++ b/framework/Image/lib/Horde/Image/Gd.php @@ -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)); }