|
使用flex的调色板传出的 color值(0x开头,十六进制),在PHP中有时需要转换,下面介绍两个非常有用的转换函数.
/* 十六进制的color值(0x开头,十六进制),6位输出,不足6位前置0 */
function _color2hex($color)
{
$len = 8 - strlen($color);
$hex = '0x';
while($len > 0)
{
$hex .= '0';
$len--;
}
$hex .= substr($color, 2);
return $hex;
}
/* 十六进制的color值转成 RGB输出 */
function _hex2rgb($hex) {
$rgb = array();
if (strtolower(substr($hex, 0, 2)) == '0x')
{
$offset = 2;
}
else
{
$offset = 0;
}
$rgb['red'] = hexdec(substr($hex, $offset, 2));
$offset += 2;
$rgb['green'] = hexdec(substr($hex, $offset, 2));
$offset += 2;
$rgb['blue'] = hexdec(substr($hex, $offset, 2));
return $rgb;
} |
|
|