0

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.

sambecker
  • 1,099
  • 12
  • 28
  • @fmw42 any idea how I take that ImageMagick CLI command and fold it into my Rails app? Thanks again for solving the tricky part! – sambecker Oct 31 '17 at 00:55
  • 1
    `@sambecker` Sorry, I do not know Rails/Ruby. But at worst, you might be able to make a call to command line ImageMagick with some kind of subprocess call (similar to PHP exec or a subprocess call from Python to ImageMagick). Also see RMagick at http://rmagick.rubyforge.org or https://rmagick.github.io – fmw42 Oct 31 '17 at 01:59
  • I think the root directory of RMagick is at https://github.com/rmagick/rmagick – fmw42 Oct 31 '17 at 02:06

2 Answers2

1

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.

sambecker
  • 1,099
  • 12
  • 28
0

I do not know RMagick, but just from reviewing the docs, you can see the equivalent commands at:

https://github.com/rmagick/rmagick (rmagick installation
https://rmagick.github.io (documentation)
https://rmagick.github.io/usage.html#reading (creating image from color)
https://rmagick.github.io/image1.html#add_profile (add profile)
https://rmagick.github.io/image3.html#pixel_color (getting color at coordinate)
fmw42
  • 46,825
  • 10
  • 62
  • 80
  • That makes sense. I'm using MiniMagick above and seem to get pretty close. Any idea why my error seems to stem from the format method? The CLI line seems pretty faithful to the original intent. – sambecker Oct 31 '17 at 02:29
  • I have not used MiniMagick before. So I do not know what to tell you. But what was the exact error message? It is possible that Minimagick uses another way to do what -format does to report the color value. You can also get the color value from parsing the output as txt: format. Also perhaps you have not specified the parameter correctly for your `c.format("%[pixel:u.p{0,0}]\n", "info:")`. Is not c.format for changing image format such as from png to jpg and not for reporting colors? See https://stackoverflow.com/questions/8894194/retrieving-the-hex-code-of-the-color-of-a-given-pixel – fmw42 Oct 31 '17 at 04:28
  • Solved it! Check out the answer above. There were two things I needed to fix. ICC handling and separating out the format arguments. Thank you for your help! – sambecker Oct 31 '17 at 04:38