$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;
}
/* 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;
}
$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;
*/
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'];
}
/**
- * 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()
*
* @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));
}
}
{
$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();
}
*/
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:
}
}
- 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));
}