note 49866 added to function.hexdec
| From: | groobo at osu1 dot php dot net | Date: | Thu, 10 Feb 2005 19:46:29 +0000 |
| Subject: | note 49866 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84809@lists.php.net to get a copy of this message | ||
It's just a revision to marfastic's ligten_up script, it simply adds/subtracts mod_color
to orig_color.
I use it often to adjust tonals rather than brightness only
<?
function mod_color($orig_color, $mod, $mod_color){
/*
$orig_color - original html color, hex
$mod_color - modifying color, hex
$mod - modifier '+' or '-'
usage: mod_color('CCCCCC', '+', '000033')
*/
// does quick validation
preg_match("/([0-9]|[A-F]){6}/i",$orig_color,$orig_arr);
preg_match("/([0-9]|[A-F]){6}/i",$mod_color,$mod_arr);
if ($orig_arr[0] && $mod_arr[0]) {
for ($i=0; $i<6; $i=$i+2) {
$orig_x = substr($orig_arr[0],$i,2);
$mod_x = substr($mod_arr[0],$i,2);
if ($mod == '+') { $new_x = hexdec($orig_x) + hexdec($mod_x); }
else { $new_x = hexdec($orig_x) - hexdec($mod_x); }
if ($new_x < 0) { $new_x = 0; }
else if ($new_x > 255) { $new_x = 255; };
$new_x = dechex($new_x);
$ret .= $new_x;
}
return $ret;
} else { return false; }
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49866
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49866&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49866&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49866&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49866&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49866&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49866&report=yes
Search -- http://master.php.net/manage/user-notes.php