将CMYK颜色值和RGB颜色相互转换的PHP代码

时间:2021-05-18

function hex2rgb($hex) {$color = str_replace('#','',$hex);$rgb = array('r' => hexdec(substr($color,0,2)),'g' => hexdec(substr($color,2,2)),'b' => hexdec(substr($color,4,2)));return $rgb;} // www.jb51.netfunction rgb2cmyk($var1,$g=0,$b=0) {if (is_array($var1)) {$r = $var1['r'];$g = $var1['g'];$b = $var1['b'];} else {$r=$var1;}$cyan = 255 - $r;$magenta = 255 - $g;$yellow = 255 - $b;$black = min($cyan, $magenta, $yellow);$cyan = @(($cyan - $black) / (255 - $black)) * 255;$magenta = @(($magenta - $black) / (255 - $black)) * 255;$yellow = @(($yellow - $black) / (255 - $black)) * 255;return array('c' => $cyan / 255,'m' => $magenta / 255,'y' => $yellow / 255,'k' => $black / 255);}$color=rgb2cmyk(hex2rgb('#FF0000'));

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章