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')); }
/** * Calculate a color that will be readable against a specific background-color. * * @param $value string the background color in question * @return string a color that is readable against this background-color. */ public static function max_readability($value) { /** * The lumosity difference between the background color and white */ $lumosity_difference_to_white = Kirki_Color::lumosity_difference($value, '#ffffff'); /** * The lumosity difference between the background color and #333 (dark grey) */ $lumosity_difference_to_black = Kirki_Color::lumosity_difference($value, '#333333'); /** * Return whitre or #333333 depending on which lumosity difference is greater. */ return $lumosity_difference_to_black > $lumosity_difference_to_white ? '#333333' : '#ffffff'; }