Last active
September 28, 2024 14:50
-
-
Save sebdesign/a65cc39e3bcd81201609e6a8087a83b3 to your computer and use it in GitHub Desktop.
Revisions
-
sebdesign revised this gist
Nov 8, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public static function rgb(string $hex): array * @param int $b * @return float */ public static function luminance(int $r, int $g, int $b): float { return 0.2126 * pow($r/255, 2.2) + 0.7152 * pow($g/255, 2.2) + @@ -35,7 +35,7 @@ public static function luminance (int $r, int $g, int $b): float * @param string $C2 hex color * @return float */ public static function relativeLuminance(string $C1, string $C2): float { $L1 = self::luminance(...self::rgb($C1)); $L2 = self::luminance(...self::rgb($C2)); -
sebdesign revised this gist
Nov 8, 2021 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,10 +5,10 @@ class Color /** * Convert a hex color to RGB. * * @param string $hex #BADA55 * @return array{int,int,int} [186, 218, 85] */ public static function rgb(string $hex): array { return sscanf($hex, "#%02x%02x%02x"); } @@ -21,7 +21,8 @@ public static function rgb ($hex) * @param int $b * @return float */ public static function luminance (int $r, int $g, int $b): float { return 0.2126 * pow($r/255, 2.2) + 0.7152 * pow($g/255, 2.2) + 0.0722 * pow($b/255, 2.2); @@ -34,7 +35,8 @@ public static function luminance ($r, $g, $b) { * @param string $C2 hex color * @return float */ public static function relativeLuminance (string $C1, string $C2): float { $L1 = self::luminance(...self::rgb($C1)); $L2 = self::luminance(...self::rgb($C2)); -
sebdesign created this gist
Jul 11, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ <?php class Color { /** * Convert a hex color to RGB. * * @param string $hex #BADA55 * @return array [186, 218, 85] */ public static function rgb ($hex) { return sscanf($hex, "#%02x%02x%02x"); } /** * Calculate the relative luminance of an RGB color. * * @param int $r * @param int $g * @param int $b * @return float */ public static function luminance ($r, $g, $b) { return 0.2126 * pow($r/255, 2.2) + 0.7152 * pow($g/255, 2.2) + 0.0722 * pow($b/255, 2.2); } /** * Calculate the relative luminance of two colors. * * @param string $C1 hex color * @param string $C2 hex color * @return float */ public static function relativeLuminance ($C1, $C2) { $L1 = self::luminance(...self::rgb($C1)); $L2 = self::luminance(...self::rgb($C2)); if ($L1 > $L2) { return ($L1 + 0.05) / ($L2 + 0.05); } else { return ($L2 + 0.05) / ($L1 + 0.05); } } }