spacious_hex2rgb( $hexstr)
-
Hi from germany,
I’d kindly like to ask you, if you could probably add a wrapper around this function, so that I could overwrite it in a child theme:
if(! function_exists('spacious_hex2rgb')): function spacious_hex2rgb( $hexstr) { ... } endif;
I like the Spacious Theme a lot, so I use it for projects frequently. But every now and then I run into trouble with your function, so I normally overwrite it with this more complex one:
function spacious_hex2rgb($color, $opacity = 0.85) { $default = 'rgb(0,0,0)'; //Return default if no color provided if(empty($color)){ return $default; } //Sanitize $color if "#" is provided if ($color[0] == '#' ) { $color = substr( $color, 1 ); } //Check if color has 6 or 3 characters and get values if (strlen($color) == 6) { $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif ( strlen( $color ) == 3 ) { $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return $default; } //Convert hexadec to rgb $rgb = array_map('hexdec', $hex); //Check if opacity is set(rgba or rgb) if($opacity){ if(abs($opacity) > 1){ $opacity = 1.0; } $output = 'rgba('.implode(",",$rgb).','.$opacity.')'; } else { $output = 'rgb('.implode(",",$rgb).')'; } //Return rgb(a) color string return $output; }
With every theme update I have to fix that again, which is a bit annoying ??
Thanks for your effort and for considering my suggestion.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘spacious_hex2rgb( $hexstr)’ is closed to new replies.