php – 使用Imagick将图像从RGB转换为CMYK

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 使用Imagick将图像从RGB转换为CMYK脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将RGB图像转换为CMYK,因为它们需要打印.
我正在使用此代码

<?PHP
$filePath = 'rgb.jpg';

// First save image as png
$image = new Imagick($filePath);
$image->setImageComPression(Imagick::COMPRESSION_UNdefineD);
$image->setImageCompressionQualITy(0); 
$image->setImageFormat("png");
$filePath = 'rgb.png';
$image->writeimage($filePath);
$image->clear();
$image->destroy();
$image = null;

// Convert colors
$image = new Imagick($filePath);
$image->stripImage();
$image->setImageColorspace(Imagick::COLORSPACE_CMYK);
$image->setImageCompression(Imagick::COMPRESSION_UNDEFINED);
$image->setImageCompressionQuality(0); 
$image->setImageFormat("png");
$filePath = 'cmyk.png';
$image->writeImage($filePath);

$image->clear();
$image->destroy();
$image = null;


$fileUrl = 'http://www.product-designer.nl/rgB2Cmyk/cmyk.png';
?>
CMYK Image:<br/>
<img src="<?PHP echo $fileUrl; ?>" width="400" /><br /><br />
<?PHP
$fileUrl = 'http://www.product-designer.nl/rgb2cmyk/rgb.png';
?>
RGB Image:<br/>
<img src="<?PHP echo $fileUrl ?>" width="400" />

你可以在http://product-designer.nl/rgb2cmyk上看到结果
我不知道怎么样,但不知何故,图像上的颜色变得颠倒了.
我需要转换图像,但颜色需要尽可能接近RGB颜色.

有谁知道如何做到一点

谢谢

解决方法

看看 here

<?PHP 
// don't use this (it inverts the image) 
//    $img->setImageColorspace (imagick::COLORSPACE_RGB); 

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) 
?>

脚本宝典总结

以上是脚本宝典为你收集整理的php – 使用Imagick将图像从RGB转换为CMYK全部内容,希望文章能够帮你解决php – 使用Imagick将图像从RGB转换为CMYK所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。