PHP IMagick RGB to CMYK inverts?

五迷三道 提交于 2019-12-06 07:37:40

问题


I'm trying to convert a RGB .gif to a CMYK .gif using IMagick PHP module.

I've wrote this piece of code

$i = new Imagick('mosaique.gif');
$i->setImageColorspace(Imagick::COLORSPACE_CMYK);
$i->setImageFormat('gif');
$i->writeImage('mosaique-cmyk.gif');

But the resultant "mosaique-cmyk.gif" still a RGB... but with inverted colors (O_O)

What am I doing wrong?

EDIT:

I've tried with a .jpg and the image is converted to CMYK but it stills in negative.

EDIT 2:

I've tried to run my script making a .pdf on another server and it works fine.

Are there any known bug in IMagick? Are there some options to set in the php5 library?

The version that returns me the inverted image is newer than the one that works correctly

WRONG RESULT PHP 5.3.3 IMagick 3.0.0RC1 ImageMagick 6.6.2

CORRECT RESULT PHP 5.2.10 IMagick 2.1.1 ImageMagick 6.5.1


回答1:


The error in fact it's a bug ;)

I reported it, some other has confirmed my fear and now it's assigned to a developer for a fix: http://pecl.php.net/bugs/bug.php?id=22184

At this moment the solution it's to use a different version of the libraries.




回答2:


GIF is 256-color format aka "indexed." I do not think one can save a gif as cmyk. Each of the 256 colors is an RGB value, but it is not capable of storing the full RGB gamut.




回答3:


Try this:

$im->stripImage();
$icc_cmyk_profile_path='image_functions/cmyk_icc_profiles/USWebUncoated.icc'; 
//[http://www.mattbeals.com/icc/][1]

$icc_cmyk = file_get_contents($icc_cmyk_profile_path);
$im->profileImage('icc', $icc_cmyk);
unset($icc_cmyk);
$colorspace=$im->getImageColorspace();                  

if ($colorspace==12) {
    echo "CMYK";
}

$im->stripImage();

$im->writeImage($destination);      
$im->clear();
$im->destroy();



回答4:


I solved this issue: Please visit my answer on this stackoverflow page: Convert image from RGB to CMYK with Imagick

(Kevin)

It is a negateImage() issue. Easy to fix.




回答5:


see here http://imagemagick.org/Usage/formats/#color_profile

convert cmyk_image.jpg -colorspace rgb rgb_image.jpg



来源:https://stackoverflow.com/questions/4830478/php-imagick-rgb-to-cmyk-inverts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!