This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.


 

Dodo's Scripts Collection


Basic TutorialsBasic Tutorials

Inverse Color
The inverse of a color is the most contrasting color of that color.

[read ONLY if you are a geek] Mathematically, it's the complement of current RGB value of the color. On the web, each color is represented in either a HEXCODE or its RGB (red, green, blue) form. The hexcode is a representation of the color's RGB value. Hex means base 16. It's consisted of 1-9 Plus A-F. Since two hex code can represent up to 256 decimals because 162 = 256 (from 0 - 255), the first two digit of the hexcode is the color's red value. The second is the green value and third is the blue value. So after we convert the hexcode representation of the color to its respective red, green and blue values and substract each from 255. Then convert them back to hex and concatenate them. We get its complement color or inverse.

Either way, if you don't know what I'm talking about, just take a look at this example. You will get it.

<?
// just returns the inverse
function inversecolor($hexcode) {
	if(substr($hexcode, 0, 1) == "#") {
		$hexcode = substr($hexcode, -6);
	}
	$r = hexdec(substr($hexcode, 0, 2));
	$g = hexdec(substr($hexcode, 2, 2));
	$b = hexdec(substr($hexcode, 4, 2));

	$strColor = "#".dechex(255 - $r).dechex(255 - $g).dechex(255 - $b);
	return $strColor;
}
?>
To call it, just do something like:

<?
echo inversecolor("#254899");
?>
It should return #DAB766. You are also welcome to grab my javascript version of this function and its demonstration.
Back