function _textimage_hex2rgb in Textimage 5.2
Same name and namespace in other branches
- 5 textimage.module \_textimage_hex2rgb()
- 6.2 textimage.module \_textimage_hex2rgb()
- 7.2 textimage.utils.inc \_textimage_hex2rgb()
Convert a hex color representation to it's rgb integer components.
Parameters
$hex: Hex representation of the color. Can be in the formats: '#ABC','ABC','#AABBCC','AABBCC' @return Array with three components RGB.
3 calls to _textimage_hex2rgb()
- textimage_image_from_preset in ./
textimage.module - Loads the Textimage preset and generates the GD image resource.
- textimage_image_stroke_change_pixels in ./
textimage.module - Utility function for image_stroke. Analyzes surrounding pixels and determines opacity of a pixel at that x-y coordinate
- textimage_text_to_image in ./
textimage.module - Generate an image containing text with the given parameters.
File
- ./
textimage.module, line 863
Code
function _textimage_hex2rgb($hex) {
$r = $g = $b = '';
$hex = ltrim($hex, '#');
if (preg_match('/^[0-9a-f]{3}$/i', $hex)) {
// 'FA3' is the same as 'FFAA33' so r=FF, g=AA, b=33
$r = str_repeat($hex[0], 2);
$g = str_repeat($hex[1], 2);
$b = str_repeat($hex[2], 2);
}
elseif (preg_match('/^[0-9a-f]{6}$/i', $hex)) {
// #FFAA33 or r=FF, g=AA, b=33
$r = drupal_substr($hex, 0, 2);
$g = drupal_substr($hex, 2, 2);
$b = drupal_substr($hex, 4, 2);
}
$r = hexdec($r);
$g = hexdec($g);
$b = hexdec($b);
return array(
$r,
$g,
$b,
);
}