note 49969 deleted from function.base-convert by danbrown
| From: | danbrown@php.net | Date: | Sat, 02 Jul 2011 15:40:54 +0000 |
| Subject: | note 49969 deleted from function.base-convert by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181173@lists.php.net to get a copy of this message | ||
Note Submitter: mike at we cant lose dot com
----
There are a few functions posted here to inverse or invert a hex color code yet none of them have
actually worked for me.
This function will take a hex color code string such as '#00FF00' and return the inversed
or inverted hex color code string of '#FF00FF'.
<?
function inverseColor($hex) {
if(substr($hex, 0, 1) == '#') $hex = substr($hex, 1);
$r = str_pad(dechex(255 - hexdec(substr($hex, 0, 2)) ),2,'0',STR_PAD_LEFT);
$g = str_pad(dechex(255 - hexdec(substr($hex, 2, 2)) ),2,'0',STR_PAD_LEFT);
$b = str_pad(dechex(255 - hexdec(substr($hex, 4, 2)) ),2,'0',STR_PAD_LEFT);
return strtoupper('#'.$r.$g.$b);
}
?>