private function _hex2rgb($color, $default_on_error = '#FFFFFF')
{
// if color is not formatted correctly
// use the default color
if (preg_match('/^#?([a-f]|[0-9]){3}(([a-f]|[0-9]){3})?$/i', $color) == 0) {
$color = $default_on_error;
}
// trim off the "#" prefix from $background_color
$color = ltrim($color, '#');
// if color is given using the shorthand (i.e. "FFF" instead of "FFFFFF")
if (strlen($color) == 3) {
$tmp = '';
// take each value
// and duplicate it
for ($i = 0; $i < 3; $i++) {
$tmp .= str_repeat($color[$i], 2);
}
// the color in it's full, 6 characters length notation
$color = $tmp;
}
// decimal representation of the color
$int = hexdec($color);
// extract and return the RGB values
return array('r' => 0xff & $int >> 0x10, 'g' => 0xff & $int >> 0x8, 'b' => 0xff & $int);
}