Skip to content

Instantly share code, notes, and snippets.

@al5dy
Last active January 2, 2018 04:55
Show Gist options
  • Save al5dy/891d2d54bcf7f6e0baeada60e3bf19c4 to your computer and use it in GitHub Desktop.
Save al5dy/891d2d54bcf7f6e0baeada60e3bf19c4 to your computer and use it in GitHub Desktop.
WordPress функция перевода HEX в RGB/A цвет
if ( ! function_exists( 'hex_to_rgb' ) ) {
function hex_to_rgb( $hex_color, $normal = false, $opacity = 1 ) {
$hex_int = hexdec( sanitize_hex_color($hex_color) );
$rgb = array( 'red' => 0xFF & ( $hex_int >> 0x10 ), 'green' => 0xFF & ( $hex_int >> 0x8 ), 'blue' => 0xFF & $hex_int );
if($normal) {
$opacity_value = is_numeric($opacity) ? $opacity : 1;
$rgb = 'rgba('. implode(',', array_values($rgb)) .','. $opacity_value .')';
}
return $rgb;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment