/**
  * Hex darker/lighter/contrast functions for colours
  *
  * @param mixed $color
  * @param int $factor (default: 30)
  * @return string
  */
 function wc_hex_lighter($color, $factor = 30)
 {
     $base = wc_rgb_from_hex($color);
     $color = '#';
     foreach ($base as $k => $v) {
         $amount = 255 - $v;
         $amount = $amount / 100;
         $amount = round($amount * $factor);
         $new_decimal = $v + $amount;
         $new_hex_component = dechex($new_decimal);
         if (strlen($new_hex_component) < 2) {
             $new_hex_component = "0" . $new_hex_component;
         }
         $color .= $new_hex_component;
     }
     return $color;
 }
 /**
  * @deprecated
  */
 function woocommerce_rgb_from_hex($color)
 {
     return wc_rgb_from_hex($color);
 }
Esempio n. 3
0
 /**
  * Test wc_rgb_from_hex().
  *
  * @since 2.2
  */
 public function test_wc_rgb_from_hex()
 {
     $rgb = array('R' => 0, 'G' => 93, 'B' => 171);
     $this->assertEquals($rgb, wc_rgb_from_hex('005dab'));
     $this->assertEquals($rgb, wc_rgb_from_hex('#005dab'));
 }