Using PHP to find a color's complement
November 22nd::2006
People know a color's complement as being the color opposite it on the color wheel. When you add these two colors together, you get a shade of gray (including white or black). I use this to find the color complement in a function. I'd like to break this out into color triads and such.
Try it out!
<?php
function getComplement($baseColor)
{
#break out into RGB format
$r = hexdec(substr($baseColor, 0, 2));
$g = hexdec(substr($baseColor, 2, 2));
$b = hexdec(substr($baseColor, 4, 2));
# sprintf is used to keep leading zeros
$complement = sprintf("%02s", dechex(255- $r));
$complement .= sprintf("%02s", dechex(255- $g));
$complement .= sprintf("%02s", dechex(255- $b));
return $complement;
}
$complement = getComplement($_GET['color']);
?>