Last active
November 17, 2023 21:57
-
-
Save Neoglyph/645d25d2b784a8fb77fd77e3bdfce006 to your computer and use it in GitHub Desktop.
Convert RGB to CMYK in PHP with Imagick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
really glad it helped you!
As for the suggestions / questions:
You're right, I misstyped, the
'../path_to_icc/Profile.icc'
should be the$iccCmyk
variable instead (will fix it in the code).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:
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.