Kirki_Color::brightness_difference PHP Méthode

brightness_difference() public static méthode

A return value of more than 125 is recommended. Combining it with the color_difference function above might make sense.
public static brightness_difference ( string $color_1 = '#ffffff', string $color_2 = '#000000' ) : string
$color_1 string The 1st color.
$color_2 string The 2nd color.
Résultat string
        public static function brightness_difference($color_1 = '#ffffff', $color_2 = '#000000')
        {
            $color_1 = self::sanitize_hex($color_1, false);
            $color_2 = self::sanitize_hex($color_2, false);
            $color_1_rgb = self::get_rgb($color_1);
            $color_2_rgb = self::get_rgb($color_2);
            $br_1 = (299 * $color_1_rgb[0] + 587 * $color_1_rgb[1] + 114 * $color_1_rgb[2]) / 1000;
            $br_2 = (299 * $color_2_rgb[0] + 587 * $color_2_rgb[1] + 114 * $color_2_rgb[2]) / 1000;
            return intval(abs($br_1 - $br_2));
        }

Usage Example

 public function test_brightness_difference()
 {
     $this->assertEquals('0', Kirki_Color::brightness_difference('fff', '#ffffff'));
     $this->assertEquals('255', Kirki_Color::brightness_difference('fff', '000'));
     $this->assertEquals('255', Kirki_Color::brightness_difference('#000000', '#ffffff'));
     $this->assertEquals('181', Kirki_Color::brightness_difference('#f2f2f2', '#c00'));
     $this->assertEquals('13', Kirki_Color::brightness_difference('#f2f2f2', '#ffffff'));
 }