php轉(zhuǎn)換顏色為其反色的方法
來源:易賢網(wǎng) 閱讀:956 次 日期:2015-04-28 14:50:06
溫馨提示:易賢網(wǎng)小編為您整理了“php轉(zhuǎn)換顏色為其反色的方法”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了php轉(zhuǎn)換顏色為其反色的方法,涉及php操作顏色數(shù)值的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了php轉(zhuǎn)換顏色為其反色的方法。分享給大家供大家參考。具體分析如下:

這段php代碼可以把一個顏色變成與之相反的顏色編碼,如:白色變成黑色,藍色變成黃色

function color_inverse($color){

$color = str_replace('#', '', $color);

if (strlen($color) != 6){ return '000000'; }

$rgb = '';

for ($x=0;$x<3;$x++){

$c = 255 - hexdec(substr($color,(2*$x),2));

$c = ($c < 0) ? 0 : dechex($c);

$rgb .= (strlen($c) < 2) ? '0'.$c : $c;

}

return '#'.$rgb;

}

//使用范例:

// black -> white

print color_inverse('#000000');

// --> returns #ffffff

// blue -> yellow

print color_inverse('#0000FF');

// --> #FFFF00

希望本文所述對大家的php程序設(shè)計有所幫助。

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:php轉(zhuǎn)換顏色為其反色的方法
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)