Skip to content

Commit

Permalink
Catch all extensions.
Browse files Browse the repository at this point in the history
What a great idea to not have a common base exception for exceptions thrown
from the imagick extension. Now we have to catch each possible exception
individually.
  • Loading branch information
yunosh committed Mar 12, 2015
1 parent 3c11991 commit e7b303f
Show file tree
Hide file tree
Showing 10 changed files with 456 additions and 332 deletions.
16 changes: 11 additions & 5 deletions framework/Image/lib/Horde/Image/Effect/Imagick/Border.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ public function apply()
$this->_params['borderwidth']
);
} else {
$this->_image->imagick->borderImage(
new ImagickPixel($this->_params['bordercolor']),
$this->_params['borderwidth'],
$this->_params['borderwidth']
);
try {
$this->_image->imagick->borderImage(
new ImagickPixel($this->_params['bordercolor']),
$this->_params['borderwidth'],
$this->_params['borderwidth']
);
} catch (ImagickPixelException $e) {
throw new Horde_Image_Exception($e);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
}
}
}
12 changes: 8 additions & 4 deletions framework/Image/lib/Horde/Image/Effect/Imagick/CenterCrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ class Horde_Image_Effect_Imagick_CenterCrop extends Horde_Image_Effect
public function apply()
{
$this->_params = new Horde_Support_Array($this->_params);
$this->_image->imagick->cropThumbnailImage(
$this->_params->width, $this->_params->height
);
$this->_image->clearGeometry();
try {
$this->_image->imagick->cropThumbnailImage(
$this->_params->width, $this->_params->height
);
$this->_image->clearGeometry();
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
}
}
36 changes: 20 additions & 16 deletions framework/Image/lib/Horde/Image/Effect/Imagick/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,29 @@ class Horde_Image_Effect_Imagick_Composite extends Horde_Image_Effect
*/
public function apply()
{
foreach ($this->_params['images'] as $image) {
$topimg = new Imagick();
$topimg->clear();
$topimg->readImageBlob($image->raw());
try {
foreach ($this->_params['images'] as $image) {
$topimg = new Imagick();
$topimg->clear();
$topimg->readImageBlob($image->raw());

/* Calculate center for composite (gravity center) */
$geometry = $this->_image->imagick->getImageGeometry();
$x = $geometry['width'] / 2;
$y = $geometry['height'] / 2;
/* Calculate center for composite (gravity center) */
$geometry = $this->_image->imagick->getImageGeometry();
$x = $geometry['width'] / 2;
$y = $geometry['height'] / 2;

if (isset($this->_params['x']) && isset($this->_params['y'])) {
$x = $this->_params['x'];
$y = $this->_params['y'];
if (isset($this->_params['x']) && isset($this->_params['y'])) {
$x = $this->_params['x'];
$y = $this->_params['y'];
}
$this->_image->_imagick->compositeImage(
$topimg,
Imagick::COMPOSITE_OVER,
$x, $y
);
}
$this->_image->_imagick->compositeImage(
$topimg,
Imagick::COMPOSITE_OVER,
$x, $y
);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
}
}
44 changes: 25 additions & 19 deletions framework/Image/lib/Horde/Image/Effect/Imagick/DropShadow.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,34 @@ public function apply()
// the distance of the shadow is determined *solely* by the sigma value
// which makes it pretty much impossible to have Imagick shadows look
// identical to Im shadows...
$shadow = $this->_image->imagick->clone();
$shadow->setImageBackgroundColor(new ImagickPixel('black'));
$shadow->shadowImage(
80,
$this->_params['fade'],
$this->_params['distance'],
$this->_params['distance']
);

$shadow->compositeImage(
$this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0
);
try {
$shadow = $this->_image->imagick->clone();
$shadow->setImageBackgroundColor(new ImagickPixel('black'));
$shadow->shadowImage(
80,
$this->_params['fade'],
$this->_params['distance'],
$this->_params['distance']
);

if ($this->_params['padding']) {
$shadow->borderImage(
$this->_params['background'],
$this->_params['padding'],
$this->_params['padding']
$shadow->compositeImage(
$this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0
);

if ($this->_params['padding']) {
$shadow->borderImage(
$this->_params['background'],
$this->_params['padding'],
$this->_params['padding']
);
}
$this->_image->imagick->clear();
$this->_image->imagick->addImage($shadow);
} catch (ImagickPixelException $e) {
throw new Horde_Image_Exception($e);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
$this->_image->imagick->clear();
$this->_image->imagick->addImage($shadow);
$shadow->destroy();

$this->_image->clearGeometry();
Expand Down

0 comments on commit e7b303f

Please sign in to comment.