setColorSpace RGB results in negative image
setColorSpace RGB results in negative image
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?
$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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: setColorSpace RGB results in negative image
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
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: setColorSpace RGB results in negative image
did you do
$im = new imagick();
$im->setImageColorSpace(imagick::COLORSPACE_RGB);
...
$im = new imagick();
$im->setImageColorSpace(imagick::COLORSPACE_RGB);
...
Re: setColorSpace RGB results in negative image
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);
$im = new imagick();
$im->setOption("pdf:use-cropbox","true");
$im->setResolution($resolution,$resolution);
$im->setImageColorSpace(Imagick::COLORSPACE_RGB);
$im->readImage($pdf_filepath);
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: setColorSpace RGB results in negative image
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);
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
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: setColorSpace RGB results in negative image
Only other thing is to try sending PM directly to the developer (mkoppanen?)
Re: setColorSpace RGB results in negative image
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
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?
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?
Mikko Koppanen
My blog: http://valokuva.org
My blog: http://valokuva.org
Re: setColorSpace RGB results in negative image
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
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
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
Cory
Re: setColorSpace RGB results in negative image
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
Thanks to Mikko, setColospace has been added to the SVN and is working great for me now!