PHP是否将ARGB转换为RGBA?

PHP是否将ARGB转换为RGBA?,php,colors,rgba,argb,Php,Colors,Rgba,Argb,需要解决方案或说明:如何将颜色值从ARGB转换为可用于css的RGBA: 示例: ARGB color : #ff502797 convert to RGBA RGBA result example: rgba(80,39,151,1) function argb2rgba($color) { $output = 'rgba(0,0,0,1)'; if (empty($color)) return $output;

需要解决方案或说明:如何将颜色值从ARGB转换为可用于css的RGBA:

示例:

ARGB color : #ff502797 convert to RGBA
RGBA result example: rgba(80,39,151,1)
function argb2rgba($color)
    {
        $output = 'rgba(0,0,0,1)';

        if (empty($color))
            return $output;

        if ($color[0] == '#') {
            $color = substr($color, 1);
        }

        if (strlen($color) == 8) { //ARGB
            $opacity = round(hexdec($color[0].$color[1]) / 255, 2);
            $hex = array($color[2].$color[3], $color[4].$color[5], $color[6].$color[7]);
            $rgb = array_map('hexdec', $hex);
            $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
        }

        return $output;
    }

thx.

ARGB包含4组十六进制值(通道):Alpha、红色、绿色和蓝色

方案: 例如:#ff502797-ARGB格式的颜色 关于职位的要素:

0,1 - Alpa  (ff)
2,3 - Red   (50)
4,5 - Green (27)
6,7 - Blue  (97)
在此之后,将每个通道转换为十进制。并将自己的位置放到RBGA中: rgba(红、绿、蓝、阿尔法)-rgba(80,39151,1)

函数示例:

ARGB color : #ff502797 convert to RGBA
RGBA result example: rgba(80,39,151,1)
function argb2rgba($color)
    {
        $output = 'rgba(0,0,0,1)';

        if (empty($color))
            return $output;

        if ($color[0] == '#') {
            $color = substr($color, 1);
        }

        if (strlen($color) == 8) { //ARGB
            $opacity = round(hexdec($color[0].$color[1]) / 255, 2);
            $hex = array($color[2].$color[3], $color[4].$color[5], $color[6].$color[7]);
            $rgb = array_map('hexdec', $hex);
            $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
        }

        return $output;
    }

“哪一个可以用于html”是指CSS吗?1)将argb颜色值拆分为单个组件,2)将组件转换为十进制值,3)输出为rgba()字符串。是的,但需要spit的“映射”。。。我喜欢并写在下面。