public function compress(EventInterface $event)
{
if ($this->level === null) {
return;
}
$image = $event->getArgument('image');
$mimeType = $image->getMimeType();
if ($mimeType === 'image/gif') {
// No need to do anything if the image is a GIF
return;
}
try {
// Levels from 0 - 100 will work for both JPEG and PNG, although the level has different
// meaning for these two image types. For PNG's a high level will mean more compression,
// which usually results in a smaller file size, as for JPEG's, a high level means a
// higher quality, resulting in a larger file size.
$this->imagick->setImageCompressionQuality($this->level);
$image->hasBeenTransformed(true);
} catch (ImagickException $e) {
throw new TransformationException($e->getMessage(), 400, $e);
}
}