Page 1 of 1
RGB to CMYK inverts?
Posted: 2011-01-28T08:59:42-07:00
by shmk
I'm trying to convert a RGB .gif to a CMYK .gif using IMagick.
I've wrote this piece of code
Code: Select all
$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
EXAMPLE FILES ATTACHED!
What am I doing wrong?
Re: RGB to CMYK inverts?
Posted: 2011-01-28T14:02:00-07:00
by fmw42
does gif support cmyk? try jpg
Re: RGB to CMYK inverts?
Posted: 2011-01-29T09:09:26-07:00
by shmk
fmw42 wrote:does gif support cmyk? try jpg
I've tried with a jpg
Code: Select all
$i = new Imagick('mosaique.jpg');
$i->setImageColorspace(Imagick::COLORSPACE_CMYK);
$i->setImageFormat('jpg');
$i->writeImage('mosaique-cmyk.jpg');
it's converted to CMYK but it is likes in negative

Re: RGB to CMYK inverts?
Posted: 2011-01-31T08:29:36-07:00
by shmk
An important update!
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
Re: RGB to CMYK inverts?
Posted: 2011-03-17T21:40:36-07:00
by fmw42
best to use profiles for conversion from rgb to cmyk
see profiles at
http://www.imagemagick.org/Usage/formats/#profiles
Re: RGB to CMYK inverts?
Posted: 2013-06-15T08:59:49-07:00
by kevin.florida
I HAVE A SOLUTION!
After 2 days of hacking and intensive research I have solved the problem. It was a very frustrating issue, so I wanted to make sure I share the solution.
Note: my Imagick object is $jpeg and you have to download the adobe AdobeRGB1998.icc profile from their website (do a google search).
Only on 5.3.x you have to negate the converted image, see my solution:
Code: Select all
$range = $jpeg->getQuantumRange();
$php_vs_arr = preg_split("/\./", phpversion());
$php_vs = $php_vs_arr[0] . '.' . $php_vs_arr[1];
if ($jpeg->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
//make sure cmyk color-space is set correctly
$jpeg->setImageColorspace(12);
// then we add an RGB profile
$icc_rgb = file_get_contents(FRAMEWORK_PATH . DS . 'color' . DS . 'AdobeRGB1998.icc');
$jpeg->profileImage('icc', $icc_rgb);
unset($icc_rgb);
//set color space to rgb
$jpeg->setImageColorspace(13);
//fix gamma, hue, saturation, brightness
if($php_vs < 5.3) {
//ADJUST GAMMA BY 2.0 for 5.2.x
$jpeg->levelImage(0, 2.0, $range['quantumRangeString']);
} else {
//php 5.3 hack FOR INVERTED COLORS
$jpeg->negateImage(false, Imagick::CHANNEL_ALL);
}
}
$jpeg->stripImage();
//end convert to RGB=========================|