From 379da044559ed88f0da0eaf0fa9c02e85a7e9041 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Thu, 6 Jul 2017 03:46:36 +0200 Subject: [PATCH] [Rule] MaxInkDensityImage - transform colorspace when necessary --- Rule/MaxInkDensityImage.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Rule/MaxInkDensityImage.php b/Rule/MaxInkDensityImage.php index 03fcb42..837a69d 100644 --- a/Rule/MaxInkDensityImage.php +++ b/Rule/MaxInkDensityImage.php @@ -26,20 +26,15 @@ public function validate(Document $document) : array foreach ($document->getObjectsByType('XObject', 'Image') as $k => $image) { $img = Utils::imageToImagick($image); + if ($img->getColorspace() != \Imagick::COLORSPACE_CMYK) { + $img->transformImageColorspace(\Imagick::COLORSPACE_CMYK); + } + // $img->getImageTotalInkDensity() returns a totally wrong value, no idea what would that mean $identity = $img->identifyImage(true); preg_match('/Total ink density: ([0-9]*(.[0-9]*)?)%/', $identity['rawOutput'], $matches); - if (!isset($matches[1])) { - $errors[] = [ - 'message' => 'Image ink density could not be determined. Not CYMK image?', - 'object' => $image, - ]; - - continue; - } - $dens = $matches[1]; if ($dens > $this->limit) {