Skip to content

Instantly share code, notes, and snippets.

@xfenix
Created June 25, 2012 12:22
Show Gist options
  • Save xfenix/2988281 to your computer and use it in GitHub Desktop.
Save xfenix/2988281 to your computer and use it in GitHub Desktop.
PHP function for bright hex color
<?
function hexLighter($hex,$factor = 30) {
$new_hex = '';
$hex = str_replace('#', '', $hex);
$base['R'] = hexdec($hex{0}.$hex{1});
$base['G'] = hexdec($hex{2}.$hex{3});
$base['B'] = hexdec($hex{4}.$hex{5});
foreach ($base as $k => $v) {
$amount = 255 - $v;
$amount = $amount / 100;
$amount = round($amount * $factor);
$new_decimal = $v + $amount;
$new_hex_component = dechex($new_decimal);
if(strlen($new_hex_component) < 2)
$new_hex_component = "0".$new_hex_component;
$new_hex .= $new_hex_component;
}
return $new_hex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment