使用ISO V2 Coated等颜色配置文件将CMYK颜色转换为RGB?

时间:2017-06-23 22:52:46

标签: javascript ruby-on-rails ruby web-services colors

我知道这个问题在几种不同的方式之前被问过,但似乎与我的问题无关:我想使用颜色配置文件(例如{{}准确地将单个CMYK颜色转换为RGB颜色1}}。我想这样做,因为直接的数学转换会导致ISO Coated V2颜色空间无法实现的鲜艳色彩。

The difference between: Real Cyan and RGB Cyan

理想情况下,这可以在Ruby中实现,但我很乐意看到伪代码甚至JavaScript的解决方案。 我宁愿避免使用依赖于专有/不透明框架的solution

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

以下方法通过CMYK/RGBRuby环境中执行ImageMagick颜色管理转换:

def convert_cmyk_to_rgb_with_profiles(cmyk, profile_1, profile_2)
  c = MiniMagick::Tool::Convert.new

  c_255 = (cmyk[:c].to_f / 100.0 * 255.0).to_i
  m_255 = (cmyk[:m].to_f / 100.0 * 255.0).to_i
  y_255 = (cmyk[:y].to_f / 100.0 * 255.0).to_i
  k_255 = (cmyk[:k].to_f / 100.0 * 255.0).to_i

  c.xc("cmyk(#{c_255}, #{m_255}, #{y_255}, #{k_255})")
  c.profile(File.open("lib/assets/profiles/#{profile_1}.icc").path)
  c.profile(File.open("lib/assets/profiles/#{profile_2}.icc").path)
  c.format("%[pixel:u.p{0,0}]\n", "info:")
  result = c.call

  srgb_values = /srgb\(([0-9.]+)%,([0-9.]+)%,([0-9.]+)%\)/.match(result)

  r = (srgb_values[1].to_f / 100.0 * 255.0).round
  g = (srgb_values[2].to_f / 100.0 * 255.0).round
  b = (srgb_values[3].to_f / 100.0 * 255.0).round

  return { r: r, g: g, b: b }
end

致电:

convert_cmyk_to_rgb_with_profiles({c:100, m:0, y:0, k:0}, "USWebCoatedSWOP", "sRGB_IEC61966-2-1_black_scaled")

此解决方案的基础以及更多细节和背景可在此处找到:

Converting colors (not images) with ImageMagick

答案 1 :(得分:0)

我假设您为CMYK显示的值是百分比(100/0/0/0)。在Imagemagick命令行中,您可以执行以下操作来制作样本

convert xc:"cmyk(100%,0%,0%,7%)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -scale 100x100! test.png

enter image description here

或者您可以按如下方式获取值:

convert xc:"cmyk(100%,0%,0%,7%)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -format "%[pixel:u.p{0,0}]\n" info:


的sRGB(0%,61%,81%)

如果你想要的值在0到255之间,而不是%,那么加上-depth 8。

convert xc:"cmyk(100%,0%,0%,7%)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -depth 8 -format "%[pixel:u.p{0,0}]\n" info:


的sRGB(0156207)

您也可以从0到255之间的值开始。

convert xc:"cmyk(255,0,0,17.85)" -profile /Users/fred/images/profiles/ISOcoated_v2_300_eci.icc -profile /Users/fred/images/profiles/sRGB.icc -depth 8 -format "%[pixel:u.p{0,0}]\n" info:


的sRGB(0156207)

你可以通过RMagick做到这一点,但我不是RMagick的专家。但请参阅sambecker中的其他帖子。