CYMK Jpeg's to RGB Png.

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
johnoyler

CYMK Jpeg's to RGB Png.

Post by johnoyler »

I'm having mixed success. Those Jpeg's that are already RGB resize fine, and I finally got the compositing done that I wanted. But every once in awhile, the final image looks like a polaroid left out in the sun for 5 weeks.

It occurred to me that some users might be uploading CYMK images from photoshop or something else. And, because I'm not doing any colorspace conversion (or even checking if it's needed), when I start all my compositing and resizing, and write it out to a PNG, it more or less dumps the K channel.

What do I need to do to account for this? Checking what colorspace an image is in seems easy enough, but it's less obvious what conversion I need to do after.

User avatar
magick
Site Admin
Posts: 11161
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Check to see if the JPEG colorspace is CMYK. If it is use Profile() to add a SWOP profile (if it does not already have one) and call Profile() again with a sRGB profile. This forces a CMYK to RGB color conversion.

johnoyler

SWOP

Post by johnoyler »

Assuming it doesn't have a SWOP profile, where can I find one? (I'm assuming it can be an external file?)

And would you be able to give some sort of pseudo-example?

Code: Select all

if ($image->Get('colorspace') eq "CMYK") {
 $image->Profile(name=>'newRGB', profile=>something);
 $image->Profile(something something?);
}
Is about the closest I can figure. Thank you for the help.

johnoyler

Ok...

Post by johnoyler »

I've reinstalled IM with the lcms library, which wasn't there. I can confirm that it's built with that now.

I've googled around, and found swop and srgb files. http://color.org had the srgb.icc file, which is probably the correct one. Finding a proper swop file was more problematic, is one as good as another?

So far, I have this:

Code: Select all

 if ($image->Get('colorspace') eq "CMYK") {
  $image->Profile(profile=>'/data/art/composite/swop.icm');
  $image->Profile(profile=>'/data/art/composite/sRGB.icc');
 }
This seems to have no effect. No errors either, but I'm still getting the same washed-out look.

Strangely, if I simply resize $image, and write it out to a png file, it's pretty good (not perfect, some reds are too bright but still good enough). It's only that I do a resize, and then start compositing png's into it, before writing to a file, that causes this. It only happens with those jpegs that I can confirm are CMYK.

What am I doing wrong?

User avatar
magick
Site Admin
Posts: 11161
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

A standard CMYK profile is USWebCoatedSWOP.icc.

Type
  • identify -list configure
Be sure -llcms is associated with the LIBS name. If its not, ImageMagick cannot apply the color transform.

johnoyler

Confirmation.

Post by johnoyler »

-llcms is associated with it. Double-checked. I've dug up a copy of the swop file you mentioned, I'm using it instead.

I'd hate to have to save the resize out to file, and re-open it before compositing just for this to work right.

johnoyler

For anyone that might have to do the same thing...

Post by johnoyler »

The trick seems to be to do the (now) obvious

Code: Select all

$image->Set(colorspace=>'RGB');
After setting the profiles. Duh. And thanks magick, I do appreciate the help you gave.

Post Reply