layers_adjust_brightness

The Layers layers adjust brightness function.

Description

layers_adjust_brightness( $color, (int) $steps = 50, (bool) $loop_back = false ); 

Parameters (3)

0. $color
The color.
1. $steps — Optional. (int) => 50
The steps.
2. $loop_back — Optional. (bool) => false
The loop back.

Usage

  1. if ( !function_exists( 'layers_adjust_brightness' ) ) { 
  2. require_once '/core/helpers/color.php'; 
  3.  
  4. // The color. 
  5. $color = null; 
  6.  
  7. // The steps. 
  8. $steps = 50; 
  9.  
  10. // The loop back. 
  11. $loop_back = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = layers_adjust_brightness($color, $steps, $loop_back); 
  15.  

Defined (1)

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

/core/helpers/color.php  
  1. function layers_adjust_brightness( $color, $steps = 50, $loop_back = false ) { 
  2.  
  3. $mod_steps = max( -255, min( 255, $steps ) ); 
  4.  
  5. $mod_color = str_replace( '#', '', $color ); 
  6. if ( strlen( $mod_color ) == 3 ) { 
  7. $mod_color = str_repeat( substr( $mod_color, 0, 1 ), 2 ) . str_repeat( substr( $mod_color, 1, 1 ), 2 ) . str_repeat( substr( $mod_color, 2, 1), 2 ); 
  8.  
  9. $mod_color_parts = str_split( $mod_color, 2 ); 
  10. $return = '#'; 
  11.  
  12. foreach ( $mod_color_parts as $mod_color ) { 
  13. $mod_color = hexdec( $mod_color ); 
  14. $mod_color = max( 0, min( 255, $mod_color + $mod_steps ) ); 
  15. $return .= str_pad( dechex( $mod_color ), 2, '0', STR_PAD_LEFT ); 
  16.  
  17. if ( ( '#000000' == $return || '#ffffff' == $return ) && $loop_back ) { 
  18. $return = layers_adjust_brightness( $color, - ( $steps ) ); 
  19.  
  20. return $return;