Created
June 29, 2020 15:43
-
-
Save ProjectCleverWeb/a1241dd39fdf06670245250822a90368 to your computer and use it in GitHub Desktop.
This file contains 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 characters
<?php | |
/** | |
* Takes an input background color and tells you if you should use a white or black for the text color | |
*/ | |
$input_color = '49DCBB'; | |
$red = base_convert(substr($input_color, 0, 2), 16, 10); | |
$green = base_convert(substr($input_color, 2, 2), 16, 10); | |
$blue = base_convert(substr($input_color, 4, 2), 16, 10); | |
$text_color = 'FFFFFF'; // use white text | |
if (((($red * 299) + ($green * 587) + ($blue * 114)) / 1000) > 127) { | |
$text_color = '000000'; // use black text | |
} | |
echo $text_color; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment