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
Rvm Ruby Installation Errors - MAC
Ruby Dsl (Domain Specific Language) Repositories, Examples
How to Wrap the Invocation of a Ruby Method by Including a Module
Rails 3. How to Add a Helper That Activeadmin Will Use
How to Set the Actionmailer Default_Url_Options's :Host Dynamically to the Request's Hostname
How to Remove a Substring After a Certain Character in a String Using Ruby
Ruby Modules and Classes Same Name in Structure
Difference Between Kernel#Yield_Self, Yield(Self), Kernel#Then and Object#Tap in Ruby
Replacing the 'Auto_Link' Method in Ruby on Rails 3.1
Rails Assets Pipeline "Cannot Allocate Memory - Nodejs"
How to Add a Virtual Attribute to a Model in Ruby on Rails
Any Way to Determine Which Object Called a Method
Importing CSV Quoting Error Is Driving Me Nuts