-
-
Save Neoglyph/645d25d2b784a8fb77fd77e3bdfce006 to your computer and use it in GitHub Desktop.
<?php | |
$iccProfile = '../path_to_icc/Profile.icc'; | |
$image = new Imagick(); | |
$image->clear(); | |
$image->readImage($imagePath); | |
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) { | |
return; | |
} | |
$iccCmyk = file_get_contents($iccProfile); | |
$image->profileImage('icc', $iccCmyk); | |
unset($iccCmyk); | |
$image->transformImageColorspace(Imagick::COLORSPACE_CMYK); | |
$image->writeImage($newImagePath); |
Hey,
really glad it helped you!
As for the suggestions / questions:
- what is the point of lines 9 and 11, and of the var $iccCmyk ?
You're right, I misstyped, the '../path_to_icc/Profile.icc'
should be the $iccCmyk
variable instead (will fix it in the code).
- the profile name argument (first of method $image->profileImage($name, $pathToProfile) must be 'cmyk', not 'icc'. An error occurs if so...
Interesting, my code contains the icc
profile parameter and does not throw an error.
Might be due to different Imagick versions, or maybe a difference in files, not too sure. For reference my Imagick is currently at:
"versionNumber" => 1673
"versionString" => "ImageMagick 6.8.9-9 Q16 x86_64 2019-11-12 http://www.imagemagick.org"
- If this transformation concerns web images, the Profile.icc must be >this file< - provided by Adobe for Web images
I actually pass different ICC Profile files based on what i'm converting the CMYK for, currently one is similar to this one: CoatedFOGRA39.icc, although I must admit I am not that knowledgeable about color profiles in general.
So you're saying, if you're receiving web images and converting them for print purposes the USWebUncoated profile is generally the recommended one? If so I might try replacing the current one i'm using with that one in the future.
Thank you ! Your piece of code actually saved me :)
This transformation functionality is clearly missing in LiipImagineBundle (in my case, in a Symfony project), surely because Imagick is not a third party dependency used everywhere ...
just few suggestions / questions :
$iccCmyk
?Profile.icc
must be >this file< - provided by Adobe for Web images