wc_rgb_from_hex

Hex darker/lighter/contrast functions for colors.

Description

(string) wc_rgb_from_hex( (mixed) $color ); 

Returns (string)

Parameters (1)

0. $color (mixed)
The color.

Usage

  1. if ( !function_exists( 'wc_rgb_from_hex' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-formatting-functions.php'; 
  3.  
  4. // The color. 
  5. $color = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_rgb_from_hex($color); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-formatting-functions.php  
  1. function wc_rgb_from_hex( $color ) { 
  2. $color = str_replace( '#', '', $color ); 
  3. // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" 
  4. $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); 
  5.  
  6. $rgb = array(); 
  7. $rgb['R'] = hexdec( $color{0} . $color{1} ); 
  8. $rgb['G'] = hexdec( $color{2} . $color{3} ); 
  9. $rgb['B'] = hexdec( $color{4} . $color{5} ); 
  10.  
  11. return $rgb;