Created
November 26, 2012 04:37
-
-
Save salmonmoose/4146634 to your computer and use it in GitHub Desktop.
Build unique colours for objects automatically
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
$background_color = substr(md5($unique_id),0,6); | |
$r = hexdec(substr($background_color,0,2)); | |
$g = hexdec(substr($background_color,2,2)); | |
$b = hexdec(substr($background_color,4,2)); | |
$l = ($r*0.2126)+($g*0.7152)+($b*0.0722); | |
$text_color = ($l >= 128)? '000000' : 'ffffff'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment