layers_hex_darker

Hex darker color function.

Description

(string) layers_hex_darker( (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( 'layers_hex_darker' ) ) { 
  2. require_once '/core/helpers/color.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 = layers_hex_darker($color, $factor); 
  12.  

Defined (1)

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

/core/helpers/color.php  
  1. function layers_hex_darker( $color, $factor = 30 ) { 
  2. $base = layers_hex2rgb( $color ); 
  3. $color = '#'; 
  4. foreach ( $base as $k => $v ) { 
  5. $amount = $v / 100; 
  6. $amount = round( $amount * $factor ); 
  7. $new_decimal = $v - $amount; 
  8. $new_hex_component = dechex( $new_decimal ); 
  9. if ( strlen( $new_hex_component ) < 2 ) { 
  10. $new_hex_component = "0" . $new_hex_component; 
  11. $color .= $new_hex_component; 
  12. return $color;