public transform ( Imbo\EventManager\EventInterface $event ) | ||
$event | Imbo\EventManager\EventInterface | The event instance |
public function transform(EventInterface $event)
{
$image = $event->getArgument('image');
$pois = $this->getPoisFromMetadata($event, $image);
if (empty($pois) || !is_array($pois)) {
return;
}
$params = $event->getArgument('params');
$color = !empty($params['color']) ? $this->formatColor($params['color']) : $this->color;
$borderSize = isset($params['borderSize']) ? (int) $params['borderSize'] : $this->borderSize;
$pointSize = isset($params['pointSize']) ? (int) $params['pointSize'] : $this->pointSize;
$imageWidth = $image->getWidth();
$imageHeight = $image->getHeight();
try {
foreach ($pois as $poi) {
if (isset($poi['width']) && isset($poi['height'])) {
$this->drawPoiRectangle($poi, $color, $borderSize - 1, $imageWidth, $imageHeight);
} else {
if (isset($poi['cx']) && isset($poi['cy'])) {
$this->drawPoiCircle($poi, $color, $borderSize, $pointSize);
} else {
throw new TransformationException('Point of interest had neither `width` and `height` nor `cx` and `cy`');
}
}
}
$image->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}
/** * @covers Imbo\Image\Transformation\DrawPois::transform */ public function testDrawPois() { return; $imagick = $this->getMock('Imagick'); $imagick->expects($this->any())->method('cropImage')->with($cropParams['width'], $cropParams['height'], $cropParams['left'], $cropParams['top']); $image = new Image(); $image->setWidth($imageDimensions['width']); $image->setHeight($imageDimensions['height']); $response = new Response(); $event = $this->getMock('Imbo\\EventManager\\Event'); $event->expects($this->at(0))->method('getArgument')->with('image')->will($this->returnValue($image)); $event->expects($this->at(1))->method('getArgument')->with('params')->will($this->returnValue($params)); $event->expects($this->at(2))->method('getResponse')->will($this->returnValue($response)); $transformation = new DrawPois(); $transformation->setImagick($imagick); $transformation->transform($event); }