将CMYK颜色值和RGB颜色相互转换的PHP代码
发布:smiling 来源: PHP粉丝网 添加日期:2021-03-26 10:20:25 浏览: 评论:0
本节主要介绍了将CMYK颜色值和RGB颜色相互转换的PHP代码,需要的朋友可以参考下。
- 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.phpfensi.com
- function 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'));
Tags: PHP颜色值转换
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)