在网页上使用CMYK [英] Use CMYK on web page

查看:182
本文介绍了在网页上使用CMYK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的网页上使用CMYK颜色。在CSS中是否有使用CMYK的方法,或者可以使用JavaScript将CMYK转换为RGB?

I need to use CMYK colors on my web page. Is there any way to use CMYK in CSS or may be convert CMYK to RGB using JavaScript?

EDIT:

我的意思是我有CMYK表示法的颜色创建算法,我需要在网页上使用它。


I mean I have colors creating algorithm in CMYK notation and I need to use it on web page.

推荐答案

方式将CMYK转换为RGB。 CYMK是减色系统,RGB是加色系统。每个都有不同的 gamground ,这意味着有一些颜色不能在其他颜色系统中表示,反之亦然。这两个都是设备相关的颜色空间,这真的意味着你真正得到什么颜色取决于你使用哪种设备来重现那种颜色,这就是为什么你有颜色配置文件为每个设备,调整如何将颜色生成更多的绝对 。

There is no perfect algorithmic way to convert CMYK to RGB. CYMK is a subtractive color system, RGB is an additive color system. Each have different gamuts, which means there are colors that just cannot be represented in the other color system and vice versa. Both are device dependent color spaces, which really means that what color you really get is dependent on which device you use to reproduce that color, which is why you have color profiles for each device that adjust how it produces color into something more "absolute".

你能做的最好的办法就是将一个空间模拟成另一个空间。

The best that you can do is approximate a simulation of one space onto the other. There is an entire field of computer science that is dedicated to this kind of work, and its non-trivial.

如果你正在寻找一个启发式的方法来做这个,那么这个工作是非常重要的。 Cyrille提供的链接是相当简单的数学,并且容易可逆地接受CYMK颜色并产生合理的RGB传真。

If you are looking for a heuristic for doing this, then the link that Cyrille provided is pretty simple math, and easily invertible to accept a CYMK color and produce a reasonable RGB facsimile.

一个非常简单的启发式是将青色映射到 0x00FFFF ,洋红色至 0xFF00FF ,黄色至 0xFFFF00 黑色(键)到 0x000000 。然后做这样的事情:

A very simple heuristic is to map cyan to 0x00FFFF, magenta to 0xFF00FF, and yellow to 0xFFFF00, and black (key) to 0x000000. Then do something like this:

function cmykToRGB(c,m,y,k) {

    function padZero(str) {
        return "000000".substr(str.length)+str
    }

    var cyan = (c * 255 * (1-k)) << 16;
    var magenta = (m * 255 * (1-k)) << 8;
    var yellow = (y * 255 * (1-k)) >> 0;

    var black = 255 * (1-k);
    var white = black | black << 8 | black << 16;

    var color = white - (cyan | magenta | yellow );

    return ("#"+padZero(color.toString(16)));


}

调用 cmykToRGB 与cmyk的范围从0.0到1.0。这应该给你一个RGB颜色代码。但是这只是一个启发式的,这些颜色空间之间的实际对话要复杂得多,并考虑到更多的变量,然后在这里表示。

invoking cmykToRGB with cmyk ranges from 0.0 to 1.0. That should give you back an RGB color code. But again this is just a heuristic, an actual conversation between these color spaces is much more complicated and takes into account a lot more variables then are represented here. You mileage may vary, and the colors you get out of this might not "look right"

jsFiddle here

这篇关于在网页上使用CMYK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆