doushaiyu5065 2014-04-17 14:40
浏览 212
已采纳

PHP将ARGB转换为RGBA? [关闭]

Need solution or description of: How to convert color value from ARGB to RGBA which is possible to use for css:

Examples:

ARGB color : #ff502797 convert to RGBA
RGBA result example: rgba(80,39,151,1)

thx.

  • 写回答

1条回答 默认 最新

  • duanlidi1051 2014-04-17 14:54
    关注

    ARGB contains 4 groups of HEX values(channels): Alpha, Red, Green, Blue.

    Scheme: Exampe: #ff502797 - color in ARGB formatt Elements on positions:

    0,1 - Alpa  (ff)
    2,3 - Red   (50)
    4,5 - Green (27)
    6,7 - Blue  (97)
    

    After this convert each channel to decimal. And putt on their places into RBGA: rgba(Red,Green,Blue,Alpha) - rgba(80,39,151,1)

    Example function:

    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;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容