function _color_pack

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

Converts an RGB triplet to a hex color.

2 calls to _color_pack()
ColorUnitTestCase::testColorPack in modules/color/color.test
_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 752

Code

function _color_pack($rgb, $normalize = FALSE) {
    $out = 0;
    foreach ($rgb as $k => $v) {
        $out |= (int) ($v * ($normalize ? 255 : 1)) << 16 - $k * 8;
    }
    return '#' . str_pad(dechex($out), 6, 0, STR_PAD_LEFT);
}

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