public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$params = $event->getArgument('params');
$color = !empty($params['color']) ? $this->formatColor($params['color']) : $this->color;
$width = isset($params['width']) ? (int) $params['width'] : $this->width;
$height = isset($params['height']) ? (int) $params['height'] : $this->height;
$mode = !empty($params['mode']) ? $params['mode'] : $this->mode;
try {
if ($mode === 'outbound') {
// Paint the border outside of the image, increasing the width/height
if ($this->imagick->getImageAlphaChannel() !== 0) {
// If we have an alpha channel and call `borderImage()`, Imagick will remove
// the alpha channel - if we have an alpha channel, use an alternative approach
$this->expandImage($color, $width, $height, $image);
} else {
// If we don't have an alpha channel, use the more cost-efficient `borderImage()`
$this->imagick->borderImage($color, $width, $height);
}
} else {
// Paint the border inside of the image, keeping the orignal width/height
$this->drawBorderInside($color, $width, $height, $image);
}
$size = $this->imagick->getImageGeometry();
$image->setWidth($size['width'])->setHeight($size['height'])->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
} catch (ImagickPixelException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}