Kirki_Color::lumosity_difference PHP Method

lumosity_difference() public static method

The returned value should be bigger than 5 for best readability.
public static lumosity_difference ( string $color_1 = '#ffffff', string $color_2 = '#000000' ) : string
$color_1 string The 1st color.
$color_2 string The 2nd color.
return string
        public static function lumosity_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);
            $l1 = 0.2126 * pow($color_1_rgb[0] / 255, 2.2) + 0.7151999999999999 * pow($color_1_rgb[1] / 255, 2.2) + 0.0722 * pow($color_1_rgb[2] / 255, 2.2);
            $l2 = 0.2126 * pow($color_2_rgb[0] / 255, 2.2) + 0.7151999999999999 * pow($color_2_rgb[1] / 255, 2.2) + 0.0722 * pow($color_2_rgb[2] / 255, 2.2);
            $lum_diff = $l1 > $l2 ? ($l1 + 0.05) / ($l2 + 0.05) : ($l2 + 0.05) / ($l1 + 0.05);
            return round($lum_diff, 2);
        }

Usage Example

コード例 #1
0
ファイル: test-kirki-color.php プロジェクト: yarwalker/ecobyt
 public function test_lumosity_difference()
 {
     $this->assertEquals('1', Kirki_Color::lumosity_difference('fff', '#ffffff'));
     $this->assertEquals('21', Kirki_Color::lumosity_difference('fff', '000'));
     $this->assertEquals('21', Kirki_Color::lumosity_difference('#000000', '#ffffff'));
     $this->assertEquals('5.23', Kirki_Color::lumosity_difference('#f2f2f2', '#c00'));
     $this->assertEquals('1.12', Kirki_Color::lumosity_difference('#f2f2f2', '#ffffff'));
 }
All Usage Examples Of Kirki_Color::lumosity_difference