Skip to content

Instantly share code, notes, and snippets.

@emanuel-sanabria-developer
Created February 5, 2014 18:33
Show Gist options
  • Save emanuel-sanabria-developer/8830183 to your computer and use it in GitHub Desktop.
Save emanuel-sanabria-developer/8830183 to your computer and use it in GitHub Desktop.
php_shade_color
function shadeColor($color, $percent) {
$num = base_convert(substr($color, 1), 16, 10);
$amt = round(2.55 * $percent);
$r = ($num >> 16) + $amt;
$b = ($num >> 8 & 0x00ff) + $amt;
$g = ($num & 0x0000ff) + $amt;
return '#'.substr(base_convert(0x1000000 + ($r<255?$r<1?0:$r:255)*0x10000 + ($b<255?$b<1?0:$b:255)*0x100 + ($g<255?$g<1?0:$g:255), 10, 16), 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment