gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 08:06:58 24 4
gpt4 key购买 nike

我知道这个问题已经被问过几个不同的方式,但似乎没有一个与我的问题相关:我想使用颜色配置文件,例如 ISO Coated V2。我想这样做是因为直接的数学转换会导致在 CMYK 颜色空间中无法实现明亮的颜色。

The difference between: Real Cyan and RGB Cyan

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

有什么想法吗?

最佳答案

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

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

关于javascript - 使用 ISO V2 Coated 等颜色配置文件将 CMYK 颜色转换为 RGB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44730949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com