Created
June 25, 2012 12:22
-
-
Save xfenix/2988281 to your computer and use it in GitHub Desktop.
PHP function for bright hex color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
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