//hex颜色加深减淡
function changeColor($hex, $type='no'){
$level = "0.8"; //level为加深的程度,限0-1之间
$diycolor = '#b4e0e1';
if($hex < 0 || hexdec($hex) > hexdec('ffffff'))
{
$hex = $diycolor;
}
$rgb = hexToRgb($hex);
if($type=='-'){ //减淡
for ($i = 0; $i < 3; $i++) {
$re[$i] = floor((255 - $rgb[$i]) * $level + $rgb[$i]);
}
$re = rgbToHex($re);
}elseif($type=='+'){ //加深
for ($i = 0; $i < 3; $i++){
$re[$i] = floor($rgb[$i] * (1 - $level));
}
$re = rgbToHex($re);
}
else{
$re = $hex;
}
return $re;
}
//hex颜色转RGB
function hexToRgb($hex){
$hex = str_replace('#', '', $hex);
$rgb[0] = hexdec($hex[0].$hex[1]);
$rgb[1] = hexdec($hex[2].$hex[3]);
$rgb[2] = hexdec($hex[4].$hex[5]);
return $rgb;
}
//RGB颜色转hex
function rgbToHex($rgb){
return sprintf('%02x', $rgb[0]) . sprintf('%02x', $rgb[1]) . sprintf('%02x', $rgb[2]);
}