Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Properly converting a CMYK image to RGB with RMagick

I have been using the below to do a color conversion

    if @image.colorspace == Magick::CMYKColorspace
      # @image.colorspace #=> CMYKColorspace=12
      @image.colorspace = Magick::RGBColorspace
      @image = @image.negate
    end

It works, approximately, but the color luminosity is off. The fact that I need to negate the image leaves a very bad smell.

The documentation mentions using color_profiles, but beyond that I can not find much.

I am now trying

@image = @image.quantize(16777216, Magick::RGBColorspace)

And the colors are better, but still off.

like image 837
The Who Avatar asked Dec 05 '09 20:12

The Who


People also ask

How do I convert RGB to CMYK without losing color in Illustrator?

Can you convert RGB to CMYK without losing color? You cannot convert between RGB and CMYK without some amount of color difference of some sort. It's a good idea to do test prints of your work with a high quality printer to see how your colors turn out.

Should I convert images to CMYK before printing?

RGB colours may look good on screen but they will need converting to CMYK for printing. This applies to any colours used in the artwork and to the imported images and files. If you are supplying artwork as a high resolution, press ready PDF then this conversion can be done when creating the PDF.


1 Answers

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 }
like image 116
The Who Avatar answered Oct 25 '22 15:10

The Who