3

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

Riccardo
  • 1,309
  • 1
  • 25
  • 35

4 Answers4

3

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.

Riccardo
  • 1,309
  • 1
  • 25
  • 35
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.

horatio
  • 1,426
  • 8
  • 7
  • I've tried with Illustrator and it convert your .gif on CMYK but when it saves the image as .gif it's back on RGB, so you're probably right! I've tried my previous example on JPG too, it's converted to CMYK but it still in negative :| – Riccardo Jan 29 '11 at 16:16
  • CMYK jpg is not universally supported either. Photoshop does, but not all software can handle it. Also, technically GIF is NOT RGB, but indexed color. You are confusing the terms. Whenever you convert back and forth from rgb to cmyk, you lose color fidelity as well. – horatio Feb 01 '11 at 17:39
1

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();
matija kancijan
  • 1,205
  • 10
  • 11
-2

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

convert cmyk_image.jpg -colorspace rgb rgb_image.jpg

Gajendra Bang
  • 3,593
  • 1
  • 27
  • 32
  • The question was about php imagick extension, not about command line "convert" of ImageMagick, so this answer is "not on topic". => -1 – griffin Jun 12 '13 at 16:39
  • php imagick is not doing it, its just a wrapper for ImageMagick and if you know the command line option, you can use it in your php code. – Gajendra Bang Nov 25 '13 at 06:40
  • It's a wrapper for the ImageMagick library, not for the convert tool. That's not the same. And the wrapper doesn't expose all options. https://github.com/mkoppanen/imagick/ you can view the source and see, that it does in fact NOT just call the cli IM commands (see imagick.c), but exposes functionality individually. – griffin Nov 26 '13 at 11:45