Skip to content

Instantly share code, notes, and snippets.

@rsky
Created July 10, 2012 13:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsky/3083319 to your computer and use it in GitHub Desktop.
Save rsky/3083319 to your computer and use it in GitHub Desktop.
PHP ImagickでCMYK色空間のJPEGファイルをsRGBに変換する
<?php
$im = new Imagick('CMYK.jpg');
$cs = $im->getImageColorspace();
if ($cs !== Imagick::COLORSPACE_RGB && $cs !== Imagick::COLORSPACE_SRGB) {
$icc = null;
try {
$icc = $im->getImageProfile('icc');
} catch (ImagickException $e) {
if ($cs === Imagick::COLORSPACE_CMYK) {
$icc = file_get_contents('JapanColor2001Coated.icc');
$im->setImageProfile('icc', $icc);
}
}
if ($icc) {
$icc = file_get_contents('sRGB_v4_ICC_preference.icc');
$im->profileImage('icc', $icc);
}
$im->setImageColorspace(Imagick::COLORSPACE_SRGB);
}
$im->writeImage('sRGB.jpg');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment