/**
* 十六进制转RGB
*
* @param string $color 16进制颜色值
* @return array
*/
public static function hex2rgb($color) {
$hexColor = str_replace('#', '', $color);
$lens = strlen($hexColor);
if ($lens != 3 && $lens != 6) {
return false;
}
$newcolor = '';
if ($lens == 3) {
for ($i = 0; $i < $lens; $i++) {
$newcolor .= $hexColor[$i] . $hexColor[$i];
}
} else {
$newcolor = $hexColor;
}
$hex = str_split($newcolor, 2);
$rgb = [];
foreach ($hex as $key => $vls) {
$rgb[] = hexdec($vls);
}
return $rgb;
}
PHP十六进制颜色转RGB颜色值
最新推荐文章于 2024-08-10 22:56:59 发布