印刷需要用到CMYK色彩模式的图片,但我们通常生成的都是RGB的图片,所以需要进行互转
public function cmyk2rgb() { $cmyk = new Imagick('/home/1.jpg'); $cs = $cmyk->getImageColorspace(); if($cs == imagick::COLORSPACE_CMYK){ die('this is CMYK'); } $profiles = $cmyk->getImageProfiles('*', false); $has_icc_profile = (array_search('icc', $profiles) !== false); if ($has_icc_profile === false) { $icc_cmyk = file_get_contents(MIO_PATH.'Lib/ICC/cmyk.icc'); $cmyk->profileImage('icc', $icc_cmyk); unset($icc_cmyk); } $icc_rgb = file_get_contents(MIO_PATH.'Lib/ICC/rgb.icc'); $cmyk->profileImage('icc', $icc_rgb); unset($icc_rgb); $cmyk->writeImage('/home/rgb.jpg'); } public function rgb2cmyk() { $rgb = new Imagick('/home/333.jpg'); $rgb->setImageResolution(300,300); $rgb->setCompression(Imagick::COMPRESSION_JPEG); $rgb->setImageCompressionQuality(100); $rgb->setCompressionQuality(100); $rgb->setImageFormat('jpg'); $rgb->stripImage(); $cs = $rgb->getImageColorspace(); if($cs == imagick::COLORSPACE_SRGB){ die('this is RGB'); } $profiles = $rgb->getImageProfiles('*', false); $has_icc_profile = (array_search('icc', $profiles) !== false); if ($has_icc_profile === false) { $icc_rgb = file_get_contents(MIO_PATH.'Lib/ICC/rgb.icc'); $rgb->profileImage('icc', $icc_rgb); unset($icc_rgb); } $icc_cmyk = file_get_contents(MIO_PATH.'Lib/ICC/cmyk.icc'); $rgb->profileImage('icc', $icc_cmyk); unset($icc_rgb); $rgb->writeImage('/home/cmyk1.jpg'); }