everbox_adjustBrightness

Adjusting color.

Description

everbox_adjustBrightness( ([type]) $hex, ([type]) $steps ); 

Parameters (2)

0. $hex ([type])
Color need to be adjusted
1. $steps ([type])
Adjust by step

Usage

  1. if ( !function_exists( 'everbox_adjustBrightness' ) ) { 
  2. require_once '/inc/customizer.php'; 
  3.  
  4. // color need to be adjusted 
  5. $hex = null; 
  6.  
  7. // adjust by step 
  8. $steps = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = everbox_adjustBrightness($hex, $steps); 
  12.  

Defined (1)

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

/inc/customizer.php  
  1. function everbox_adjustBrightness($hex, $steps) { 
  2. // Steps should be between -255 and 255. Negative = darker, positive = lighter 
  3. $steps = max(-255, min(255, $steps)); 
  4.  
  5. // Normalize into a six character long hex string 
  6. $hex = str_replace('#', '', $hex); 
  7. if (strlen($hex) == 3) { 
  8. $hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2); 
  9.  
  10. // Split into three parts: R, G and B 
  11. $color_parts = str_split($hex, 2); 
  12. $return = '#'; 
  13.  
  14. foreach ($color_parts as $color) { 
  15. $color = hexdec($color); // Convert to decimal 
  16. $color = max(0, min(255, $color + $steps)); // Adjust color 
  17. $return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code 
  18.  
  19. return $return;