Skip to content

Commit

Permalink
[Rule] MaxInkDensityImage - transform colorspace when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Padam87 committed Jul 6, 2017
1 parent f33fe7a commit 379da04
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions Rule/MaxInkDensityImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 379da04

Please sign in to comment.