Page 1 of 1

setColorSpace RGB results in negative image

Posted: 2010-03-04T12:42:31-07:00
by adrianj
I am having some weird results trying to ensure that my PDF to JPG conversion results in RGB JPGs. If the PDF is RGB, then everything is fine, but if it is CMYK, then the resulting JPG looks like a negative. Without the setImageColorSpace, the JPG works fine (although it has a pinkish hue to it), but IE complains and won't display CMYK images, so I need to get them as RGB. If I do a "mogrify -colorspace RGB" on the CMYK JPG that was created via imagick, then it works fine, so I am thinking there is something wrong with imagick. This is what I am doing:

$im = new imagick();
$im->setOption("pdf:use-cropbox","true");
$im->setResolution(288,288);
$im->readImage($pdf_filepath);
$geometry=$im->getImageGeometry();
$width = ceil($geometry['width'] / ($resolution/72));
$height = ceil($geometry['height'] / ($resolution/72));

$im->setImageColorSpace(imagick::COLORSPACE_RGB);
$im->setImageFormat("jpg");

$im->scaleImage($width, $height);
$im->writeImage($jpg_filepath);




I even tried creating the CMYK JPG, and then simply doing this:

$im = new imagick($jpg_filepath);
$im->setImageColorSpace(imagick::COLORSPACE_RGB);
$im->writeImage($jpg_filepath);

but this has the same result - the image looks like a negative.

Any ideas please? Do I have something wrong with my approach?

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T09:49:38-07:00
by fmw42
I don't use any API's but in command line, when reading a cmyk pdf, you need to set the colorspace to RGB before reading the pdf.

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T11:29:12-07:00
by adrianj
Thanks for the suggestion, but I tried that as one of my many combinations and it results in this error message:

PHP Fatal error: Uncaught exception 'ImagickException' with message 'Can not process empty Imagick object' in .....

I almost wonder whether there needs to be setColorSpace rather than the setImageColorSpace so that it can set the color space of the object that the PDF will be placed into.

Surely there must be someone out there who has dealt with this :)

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T11:41:00-07:00
by fmw42
did you do

$im = new imagick();
$im->setImageColorSpace(imagick::COLORSPACE_RGB);
...

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T11:44:51-07:00
by adrianj
This is the order of what I tried

$im = new imagick();
$im->setOption("pdf:use-cropbox","true");
$im->setResolution($resolution,$resolution);
$im->setImageColorSpace(Imagick::COLORSPACE_RGB);
$im->readImage($pdf_filepath);

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T15:40:32-07:00
by fmw42
I really don't know the Imagick API well, but it looks reasonable. Sorry I am out of suggestions.

check out http://us2.php.net/manual/en/function.i ... rspace.php

Looks like it wants an integer for the colorspace

$im->setImageColorSpace(1);

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T15:56:47-07:00
by adrianj
I really appreciate all your thoughts - it is a shame that there is not a more active support forum for imagick.

I have tried the integer option already - from what I can tell, it can accept both options). Unfortunately it results in the negative looking image as well. I even tried 'negate' in an effort to convert the output back!

Guess I'll wait and hope someone else stumbles across this. I am beginning to think it is a bug in imagick. I tried upgrading to the new RC, but no change.

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T16:06:11-07:00
by fmw42
Only other thing is to try sending PM directly to the developer (mkoppanen?)

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T16:15:23-07:00
by adrianj
I am always hesitant to do that, but in this case I think you're right - I just PM's Mikko - if he gets back to me by PM, rather than here I'll post the resolution.

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T16:58:49-07:00
by mkoppanen
Hello,

looks like set/getColorSpace is missing from Imagick which are needed for setting colorspace before reading an image. I'll add these methods tomorrow. Can someone confirm in which version of ImagickMagick they were added or have I just missed them from the start?

Re: setColorSpace RGB results in negative image

Posted: 2010-03-15T17:13:33-07:00
by adrianj
Mikko,

Thanks for taking care of this so quickly. Glad to hear I wasn't missing something and that does definitely explain things - before reading the image made sense, and I figured setColorspace would be needed for that.

Not sure when it was made available, but -colorspace is referenced in the changelog back in June 2008:

2008-06-03 6.4.1-6 Cristy <quetzlzacatenango@image...>
# The -colorspace option is an operator, not a setting.

Thanks again,
Adrian

Re: setColorSpace RGB results in negative image

Posted: 2010-03-26T15:07:44-07:00
by olwildcory723
I too am in need of changing colorspaces. I receive JPEG images in CMYK, ProPhoto etc. colorspaces and I need to convert them to sRGB colorspace. Has there been a resolution to this? Do I need to re-install anything? Thanks in advance :)

Cory

Re: setColorSpace RGB results in negative image

Posted: 2010-05-14T19:00:38-07:00
by adrianj
Looks like we are still waiting on Mikko to implement this. I actually just took a look at MagicWand and they don't appear to have implemented setColorspace yet either (at least according to the docs). This is definitely making me thing I am going to have to start running exec to get this working.I could live with cmyk, but IE won't display them!

Re: setColorSpace RGB results in negative image

Posted: 2010-05-27T11:56:54-07:00
by adrianj
Thanks to Mikko, setColospace has been added to the SVN and is working great for me now!