You are here

function color_field_rgb2hex in Color Field 8

Same name and namespace in other branches
  1. 7.2 color_field.module \color_field_rgb2hex()
  2. 7 color_field.module \color_field_rgb2hex()

Helper: Convert RGB to HEX6

Parameters

$rgb Must be an array indexed on r, g and b.:

File

./color_field.module, line 40
An color field with a custom color picker using the Field Types API.

Code

function color_field_rgb2hex($rgb = FALSE) {
  $hex = '';
  $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
  $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
  $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
  return $hex;

  // returns the hex value including the number sign (#)
}