imagick CMKY转RGB CMKY too RGB
做项目的过程中发现了一个问题。 用 imagick 处理图片时候发现有几个 处理不了 一看是 CMYK 的。。
缩略图格式还是CMYK 的 但IE 游览不了 。
现提供 CMYK 转GBK CODE 同时也做下笔记。
。。。前面部分略。。。保存图片上面添加如下:
<?php // don't use this (it inverts the image) // $img->setImageColorspace (imagick::COLORSPACE_RGB); //RBG转CMYK /* if ($logo->getImageColorspace() == \Imagick::COLORSPACE_CMYK) { $logo->transformimagecolorspace(\Imagick::COLORSPACE_SRGB); } */ if ($img->getImageColorspace() == Imagick::COLORSPACE_CMYK) { $profiles = $img->getImageProfiles('*', false); // we're only interested if ICC profile(s) exist $has_icc_profile = (array_search('icc', $profiles) !== false); // if it doesnt have a CMYK ICC profile, we add one if ($has_icc_profile === false) { $icc_cmyk = file_get_contents(dirname(__FILE__).'/USWebUncoated.icc'); $img->profileImage('icc', $icc_cmyk); unset($icc_cmyk); } // then we add an RGB profile $icc_rgb = file_get_contents(dirname(__FILE__).'/sRGB_v4_ICC_preference.icc'); $img->profileImage('icc', $icc_rgb); unset($icc_rgb); } $img->stripImage (); // this will drop down the size of the image dramatically (removes all profiles) ?>
关于ICC 文件 提供地址可以下载:
CMYK: http://www.mattbeals.com/icc/profiles/cmyk/USWebUncoated.icc.zip
RGB:http://www.mattbeals.com/icc/profiles/rgb/AdobeRGB1998.icc.zip