wc_hex_lighter

Hex darker/lighter/contrast functions for colors.

Description

(string) wc_hex_lighter( (mixed) $color, (int) $factor = 30 ); 

Returns (string)

Parameters (2)

0. $color (mixed)
The color.
1. $factor — Optional. (int) => 30
(default: 30)

Usage

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

Defined (1)

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

/includes/wc-formatting-functions.php  
  1. function wc_hex_lighter( $color, $factor = 30 ) { 
  2. $base = wc_rgb_from_hex( $color ); 
  3. $color = '#'; 
  4.  
  5. foreach ( $base as $k => $v ) { 
  6. $amount = 255 - $v; 
  7. $amount = $amount / 100; 
  8. $amount = round( $amount * $factor ); 
  9. $new_decimal = $v + $amount; 
  10.  
  11. $new_hex_component = dechex( $new_decimal ); 
  12. if ( strlen( $new_hex_component ) < 2 ) { 
  13. $new_hex_component = "0" . $new_hex_component; 
  14. $color .= $new_hex_component; 
  15.  
  16. return $color;