forked from omeka/theme-thanksroy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
27 lines (24 loc) · 834 Bytes
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/**
* Modify a hex color by the given number of steps (out of 255).
*
* Adapted from a solution by Torkil Johnsen.
*
* @param string $color
* @param int $steps
* @link http://stackoverflow.com/questions/3512311/how-to-generate-lighter-darker-color-with-php
*/
function thanksroy_brighten($color, $steps) {
$steps = max(-255, min(255, $steps));
$hex = str_replace('#', '', $color);
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
$r = max(0,min(255,$r + $steps));
$g = max(0,min(255,$g + $steps));
$b = max(0,min(255,$b + $steps));
$r_hex = str_pad(dechex($r), 2, '0', STR_PAD_LEFT);
$g_hex = str_pad(dechex($g), 2, '0', STR_PAD_LEFT);
$b_hex = str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
return '#'.$r_hex.$g_hex.$b_hex;
}