CMYK values as background Color

元气小坏坏 提交于 2021-02-16 19:45:21

问题


I have to set backgroundColor of div using RGB values . Im able to get this way.

<div style="width: 100px; height: 100px; background-color: rgb(255,0,0)">
</div>

Now, Since I also have CMYK (0,1,0.5,0) values , So Can you assist me how to achieve same with these values.

Im doing this way , but no gain .

<div style="width: 100px; height: 100px; background-color: device-cmyk(0, 1, 0.5, 0)">
</div>

Thanks


回答1:


You can't do it directly in CSS. You'll have to convert your CMYK values to their RGB counterparts somewhere else (probably by a server-side script) and use the converted values in your CSS. Note that converting is not actually much different to what the SVG function does.




回答2:


You can use this PHP function or use similar algorithm to implemented by client script language:

function cmyk_to_rgb2($c, $m, $y, $k)
{
    $c = (255 * $c) / 100;
    $m = (255 * $m) / 100;
    $y = (255 * $y) / 100;
    $k = (255 * $k) / 100;

    $r = round(((255 - $c) * (255 - $k)) / 255) ;
    $g = round((255 - $m) * (255 - $k) / 255) ;
    $b = round((255 - $y) * (255 - $k) / 255) ; 

    $o->r = $r ;
    $o->g = $g ;
    $o->b = $b ;

    return $o ;
}

PHP, JavaScript



来源:https://stackoverflow.com/questions/12322208/cmyk-values-as-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!