helpers.php für Farbverlauf

This commit is contained in:
Borgal
2025-08-16 00:08:13 +02:00
parent f0ab5d8230
commit 991a6cbb01

18
inc/helpers.php Executable file
View File

@@ -0,0 +1,18 @@
<?php
function darken_color($hex, $darken_amount = 40)
{
$hex = str_replace('#', '', $hex);
if (strlen($hex) == 3) {
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
}
$rgb['r'] = hexdec(substr($hex, 0, 2));
$rgb['g'] = hexdec(substr($hex, 2, 2));
$rgb['b'] = hexdec(substr($hex, 4, 2));
foreach ($rgb as &$value) {
$value = max(0, $value - $darken_amount);
}
return '#' . str_pad(dechex($rgb['r']), 2, '0', STR_PAD_LEFT) . str_pad(dechex($rgb['g']), 2, '0', STR_PAD_LEFT) . str_pad(dechex($rgb['b']), 2, '0', STR_PAD_LEFT);
}