Commit 027b4b95 authored by targoo's avatar targoo

add helpers to convert rgb to hex6 and the other way

parent b92dba25
......@@ -679,3 +679,27 @@ function color_field_widget_error($element, $error, $form, &$form_state) {
}
}
/**
* Helper: Convert RGB to HEX6
*
* @param $rgb Must be an array indexed on r, g and b.
*/
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 (#)
}
/**
* Helper: Convert HEX6 to RGB
*
* @param $hex.
*/
function color_field_hex2rgb($hex = FALSE) {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,-2));
return compact('r', 'g', 'b');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment