Skip to content

Instantly share code, notes, and snippets.

@salmonmoose
Created November 26, 2012 04:37
Show Gist options
  • Save salmonmoose/4146634 to your computer and use it in GitHub Desktop.
Save salmonmoose/4146634 to your computer and use it in GitHub Desktop.
Build unique colours for objects automatically
$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