Created
July 17, 2015 13:41
-
-
Save kirilkirkov/239bb79bf186962af76d to your computer and use it in GitHub Desktop.
Give rgb color and percent and function will return you same color but brighter according to percent. From 0% to 100%. Example: <?php echo rgb_gen('64,128,0', '50%'); ?>
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
<?php | |
function rgb_gen($rgb, $percent) { | |
$cleaned_percent = preg_replace("/\..*|%/", "", $percent); | |
$rgb_increment = 100 - $cleaned_percent; | |
$rgb_arr = explode(',', $rgb); | |
$rgb_arr[0] + $rgb_increment <= 255 ? $rgb_arr[0]+=$rgb_increment : $rgb_arr[0] = 255; | |
$rgb_arr[1] + $rgb_increment <= 255 ? $rgb_arr[1]+=$rgb_increment : $rgb_arr[1] = 255; | |
$rgb_arr[2] + $rgb_increment <= 255 ? $rgb_arr[2]+=$rgb_increment : $rgb_arr[2] = 255; | |
$new_rgb = implode(',', $rgb_arr); | |
return $new_rgb; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment