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

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.

图片转代码服务由CSDN问答提供 功能建议

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

示例:

  ARGB颜色:#ff502797转换为RGBA 
RGBA结果示例: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;
        }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题