English 中文(简体)
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.

最佳回答

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 }
问题回答

I ve spent a long time trying to go from a CMYK EPS to a RGB PNG using RMagick and Rails. Hopefully this will be of use to someone:

def convert_image_from_cmyk_to_rgb( image )
  #puts image.alpha?
  if image.colorspace == Magick::CMYKColorspace
    image.strip!
    image.add_profile("#{Rails.root}/lib/USWebCoatedSWOP.icc")
    image.colorspace == Magick::SRGBColorspace
    image.add_profile("#{Rails.root}/lib/sRGB.icc")
  end
  image
end

You can download the ICC files direct from Adobe at http://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html

The only thing I haven t been able to suss is how to maintain transparency. The EPS I want to use has a transparent background which is being turned into white. Unfortunately I can t do something like image.transparent( "white" ) as I have white in the image that I want to keep as white.

If I uncomment the puts image.alpha? in the above code it returns false.

Does anyone know if what I m trying to do is possible with the current version of RMagick, as I m beginning to wonder if importing CMYK EPSs with transparency isn t supported.

Thanks!

The incoming files, in this case, do have a profile. I will investigate some more. I got lost with the color profiles (like where do I download them? the ICC site was not much help)

You are not the only one confused; I was too. There are discussions on the ImageMagick site that might be worth siftirng through: Here As far as I understood back then, properly working with profiles is possible when the profile used can be identified (e.g. a monitor profile) or is embedded in the file (which can be done at least for TIFF and JPG in Photoshop, I think). Check e.g. this: Here. Good luck.

I found that The Who s command line solution worked beautifully, but the RMagick solution did not work for me.

To get it to work in RMagick, I instead I had to use the Magick::Image#add_format method, which, according to the docs, will allow you to specify an source and destination profile. It looks like this:

if img.colorspace == Magick::CMYKColorspace
  img.add_profile(RGB_COLOR_PROFILE)
end 

RE: LCMS on Centos 5.5, be sure to download and build the latest LCMS from source (vs. yum install). Otherwise, IM won t find LCMS at build and you ll be scratching your head, like me, wondering why LCMS isn t included in IM delegate libs.





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签