Kirki_Color::mix_colors PHP Метод

mix_colors() публичный статический Метод

The "percentage" variable is the percent of the first color. to be used it the mix. default is 50 (equal mix).
public static mix_colors ( string | false $hex1, string | false $hex2, integer $percentage ) : string
$hex1 string | false Color.
$hex2 string | false Color.
$percentage integer A value between 0 and 100.
Результат string Returns hex color.
        public static function mix_colors($hex1, $hex2, $percentage)
        {
            $hex1 = self::sanitize_hex($hex1, false);
            $hex2 = self::sanitize_hex($hex2, false);
            $red = ($percentage * hexdec(substr($hex1, 0, 2)) + (100 - $percentage) * hexdec(substr($hex2, 0, 2))) / 100;
            $green = ($percentage * hexdec(substr($hex1, 2, 2)) + (100 - $percentage) * hexdec(substr($hex2, 2, 2))) / 100;
            $blue = ($percentage * hexdec(substr($hex1, 4, 2)) + (100 - $percentage) * hexdec(substr($hex2, 4, 2))) / 100;
            $red_hex = str_pad(dechex($red), 2, '0', STR_PAD_LEFT);
            $green_hex = str_pad(dechex($green), 2, '0', STR_PAD_LEFT);
            $blue_hex = str_pad(dechex($blue), 2, '0', STR_PAD_LEFT);
            return self::sanitize_hex($red_hex . $green_hex . $blue_hex);
        }

Usage Example

 public function get_colors()
 {
     $color = $this->get_admin_colors();
     $config = apply_filters('kirki/config', array());
     // Calculate the accent color
     $this->color_accent = isset($color['colors']) && isset($color['colors'][3]) ? $color['colors'][3] : '#3498DB';
     if (isset($config['color_accent'])) {
         $this->color_accent = Kirki_Color::sanitize_hex($config['color_accent']);
     }
     // Calculate the background & font colors
     $this->color_back = false;
     $this->color_font = false;
     if (isset($config['color_back'])) {
         $this->color_back = Kirki_Color::sanitize_hex($config['color_back']);
         $this->color_font = 170 > Kirki_Color::get_brightness($this->color_back) ? '#f2f2f2' : '#222';
     }
     $this->border_color = 170 > Kirki_Color::get_brightness($this->color_back) ? 'rgba(255,255,255,.2)' : 'rgba(0,0,0,.2)';
     $this->buttons_color = 170 > Kirki_Color::get_brightness($this->color_back) ? Kirki_Color::adjust_brightness($this->color_back, 80) : Kirki_Color::adjust_brightness($this->color_back, -80);
     $this->controls_color = 170 > Kirki_Color::get_brightness($this->color_accent) ? '#ffffff;' : '#333333';
     $this->arrows_color = 170 > Kirki_Color::get_brightness($this->color_back) ? Kirki_Color::adjust_brightness($this->color_back, 120) : Kirki_Color::adjust_brightness($this->color_back, -120);
     $this->color_accent_text = 170 > Kirki_Color::get_brightness($this->color_accent) ? Kirki_Color::adjust_brightness($this->color_accent, 120) : Kirki_Color::adjust_brightness($this->color_accent, -120);
     $this->section_background_color = Kirki_Color::mix_colors($this->color_back, '#ffffff', 10);
 }
All Usage Examples Of Kirki_Color::mix_colors