Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Created July 17, 2015 13:41
Show Gist options
  • Save kirilkirkov/239bb79bf186962af76d to your computer and use it in GitHub Desktop.
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%'); ?>
<?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