【问题标题】:PHP convert ARGB to RGBA? [closed]PHP将ARGB转换为RGBA? [关闭]
【发布时间】:2014-04-17 14:40:06
【问题描述】:

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

示例:

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

谢谢。

【问题讨论】:

  • "which is possible to use for html" 你的意思是 CSS 吗?
  • 1) 将 argb 颜色值拆分为单独的组件,2) 将组件转换为十进制值,3) 输出为 rgba() 字符串。
  • 是的,但需要吐痰的“地图”...我喜欢并写了底部。

标签: php colors rgba argb


【解决方案1】:

ARGB 包含 4 组 HEX 值(通道):Alpha、Red、Green、Blue。

方案: 示例:#ff502797 - ARGB 格式的颜色 位置元素:

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

在此之后将每个通道转换为十进制。并将他们的位置放入 RBGArgba(Red,Green,Blue,Alpha) - 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;
    }

【讨论】:

    猜你喜欢
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多