Properly Converting a Cmyk Image to Rgb with Rmagick

Properly converting a CMYK image to RGB with RMagick

Thanks Pekka, you tipped me off to the answer (+1).

You must have ImageMagick compiled with the Little Color Management System (LCMS) installed. This may already be the case if an installer or package was used. But I was compiling from source. It was as simple as installing LCMS from source and rebuilding ImageMagick (./configure; make; make install).

In ImageMagick the below works well to reproduce accurate color:

convert FILENAME -profile /PATH_TO_PROFILE/sRGB.icm OUT.jpg

So in RMagick I use the below:

if @image.colorspace == Magick::CMYKColorspace
# Adjust the path as necessary
@image.color_profile ="/usr/local/share/ImageMagick-6.5.4/config/sRGB.icm"
end

@image.write("out.jpg") { self.quality = 85 }

Rmagick / ImageMagick image creation using CMYK

As answered by the admin in the official ImageMagick-Forum the drawing engine of ImageMagick only works in sRGB colorspace. So the only solution to your issue is probably to draw in sRGB and then transform the whole image to CMYK.

How to convert sRGB to CMYK is described in this post

ruby - Dragonfly - Force CMYK to RGB conversion when doing thumbnails

Unfortunately there doesn't seem to be a straightforward way to do this with Dragonfly. I've given up.

JMagick - How to convert a picture from CMYK to RGB?

Update: You are using GIF images. They don't support "CMYK" so the transform won't work for you (see this forum post at imagemagick's web site)!


Use MagicImage.rgbTransformImage(ColorspaceType.CMYKColorspace). From the API:

public boolean rgbTransformImage(int colorspace) throws MagickException

Converts the reference image from RGB to an alternate colorspace. The transformation matrices are not the standard ones: the weights are rescaled to normalized the range of the transformed values to be [0..MaxRGB].


Example:

try {
MagickImage image = new MagickImage(new ImageInfo(baseName + fileName));

if (!image.rgbTransformImage(ColorspaceType.CMYKColorspace))
throw new Exception("Couldn't convert image color space");

...
} catch (MagickException e) {
...
}


Related Topics



Leave a reply



Submit