| 1 |
<?php |
| 2 |
|
| 3 |
// don't load directly |
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
|
| 7 |
// Color Pallete - Light Colors |
| 8 |
function luminanceLight($hexcolor, $percent) |
| 9 |
{ |
| 10 |
if ( strlen( $hexcolor ) < 6 ) { |
| 11 |
$hexcolor = $hexcolor[0] . $hexcolor[0] . $hexcolor[1] . $hexcolor[1] . $hexcolor[2] . $hexcolor[2]; |
| 12 |
} |
| 13 |
$hexcolor = array_map('hexdec', str_split( str_pad( str_replace('#', '', $hexcolor), 6, '0' ), 2 ) ); |
| 14 |
|
| 15 |
foreach ($hexcolor as $i => $color) { |
| 16 |
$from = $percent < 0 ? 0 : $color; |
| 17 |
$to = $percent < 0 ? $color : 255; |
| 18 |
$pvalue = ceil( ($to - $from) * $percent ); |
| 19 |
$hexcolor[$i] = str_pad( dechex($color + $pvalue), 2, '0', STR_PAD_LEFT); |
| 20 |
} |
| 21 |
|
| 22 |
return '#' . implode($hexcolor); |
| 23 |
} |
| 24 |
|
| 25 |
// Color Pallete - Dark Colors |
| 26 |
function luminanceDark($hexcolor, $percent) |
| 27 |
{ |
| 28 |
if ( strlen( $hexcolor ) < 6 ) { |
| 29 |
$hexcolor = $hexcolor[0] . $hexcolor[0] . $hexcolor[1] . $hexcolor[1] . $hexcolor[2] . $hexcolor[2]; |
| 30 |
} |
| 31 |
$hexcolor = array_map('hexdec', str_split( str_pad( str_replace('#', '', $hexcolor), 6, '0' ), 2 ) ); |
| 32 |
|
| 33 |
foreach ($hexcolor as $i => $color) { |
| 34 |
$from = $percent < 0 ? 0 : $color; |
| 35 |
$to = $percent < 0 ? $color : 0; |
| 36 |
$pvalue = ceil( ($to - $from) * $percent ); |
| 37 |
$hexcolor[$i] = str_pad( dechex($color + $pvalue), 2, '0', STR_PAD_LEFT); |
| 38 |
} |
| 39 |
|
| 40 |
return '#' . implode($hexcolor); |
| 41 |
} |