function _color_unpack

Same name in other branches
  1. 9 core/modules/color/color.module \_color_unpack()
  2. 8.9.x core/modules/color/color.module \_color_unpack()

Converts a hex color into an RGB triplet.

4 calls to _color_unpack()
ColorUnitTestCase::testColorUnpack in modules/color/color.test
_color_blend in modules/color/color.module
Blends two hex colors and returns the GD color.
_color_gd in modules/color/color.module
Converts a hex triplet into a GD color.
_color_shift in modules/color/color.module
Shifts a given color, using a reference pair and a target blend color.

File

modules/color/color.module, line 736

Code

function _color_unpack($hex, $normalize = FALSE) {
    $hex = substr($hex, 1);
    if (strlen($hex) == 3) {
        $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
    }
    $c = hexdec($hex);
    for ($i = 16; $i >= 0; $i -= 8) {
        $out[] = ($c >> $i & 0xff) / ($normalize ? 255 : 1);
    }
    return $out;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.