Search code examples
ruby-on-railsherokuimagemagickminimagickcolor-profile

Translate ImageMagick CLI into MiniMagick gem


I finally figured out how to convert a CMYK color into an RGB value using color profiles and ImageMagick (Converting colors (not images) with ImageMagick).

Now I'm struggling to incorporate the following command into a Rails app using MiniMagick:

magick convert xc:"cmyk(255,0,0,0)" -profile USWebCoatedSWOP.icc -profile sRGB_IEC61966-2-1_black_scaled.icc -format "%[pixel:u.p{0,0}]\n" info:

Which should return something like this:

srgb(0%,68.0964%,93.8003%)

Any ideas? I would be happy to just paste the line in directly but I'm not sure if that's how MiniMagick works. I'm also not sure how well this will run on the Heroku platform.

Any help would be appreciated.


Solution

  • Solved it:

    c = MiniMagick::Tool::Convert.new
    c.xc("cmyk(255,0,0,0)")
    c.profile(File.open("lib/assets/USWebCoatedSWOP.icc").path)
    c.profile(File.open("lib/assets/sRGB_IEC61966-2-1_black_scaled.icc").path)
    c.format("%[pixel:u.p{0,0}]\n", "info:")
    c.call
    

    The trick was locating accurate profile paths and then entering "info:" as a separate second argument in the format method.