Font colour based on background colour

Very simple little php function that returns a black or white colour depending on the darkness of the given html colour.

function fontColour($colour){
	$r = hexdec($colour[0].$colour[1]);
	$g = hexdec($colour[2].$colour[3]);
	$b = hexdec($colour[4].$colour[5]);
	$sum = $r+$g+$b;
	if($sum>390){ return '000000'; }else{ return 'FFFFFF'; }
}

as i said, simple :P
enter a 6 char html background colour and it returns 000000 or FFFFFF for your text.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word