2
0
forked from Wavyzz/dolibarr

NEW webportal v2

This commit is contained in:
VESSILLER
2023-09-28 10:44:22 +02:00
parent 54bae2e5e2
commit 004782b5bb
32 changed files with 964 additions and 767 deletions

View File

@@ -2586,6 +2586,62 @@ function colorHexToRgb($hex, $alpha = false, $returnArray = false)
}
}
/**
* Color Hex to Hsl (used for style)
*
* @param string $hex Color in hex
* @param float|false $alpha 0 to 1 to add alpha channel
* @param bool $returnArray true=return an array instead, false=return string
* @return string|array String or array
*/
function colorHexToHsl($hex, $alpha = false, $returnArray = false)
{
$hex = str_replace('#', '', $hex);
$red = hexdec(substr($hex, 0, 2)) / 255;
$green = hexdec(substr($hex, 2, 2)) / 255;
$blue = hexdec(substr($hex, 4, 2)) / 255;
$cmin = min($red, $green, $blue);
$cmax = max($red, $green, $blue);
$delta = $cmax - $cmin;
if ($delta == 0) {
$hue = 0;
} elseif ($cmax === $red) {
$hue = (($green - $blue) / $delta);
} elseif ($cmax === $green) {
$hue = ($blue - $red) / $delta + 2;
} else {
$hue = ($red - $green) / $delta + 4;
}
$hue = round($hue * 60);
if ($hue < 0) {
$hue += 360;
}
$lightness = (($cmax + $cmin) / 2);
$saturation = $delta === 0 ? 0 : ($delta / (1 - abs(2 * $lightness - 1)));
if ($saturation < 0) {
$saturation += 1;
}
$lightness = round($lightness*100);
$saturation = round($saturation*100);
if ($returnArray) {
return array(
'h' => $hue,
'l' => $lightness,
's' => $saturation,
'a' => $alpha === false ? 1 : $alpha
);
} elseif ($alpha) {
return 'hsla('.$hue.', '.$saturation.', '.$lightness.' / '.$alpha.')';
} else {
return 'hsl('.$hue.', '.$saturation.', '.$lightness.')';
}
}
/**
* Applies the Cartesian product algorithm to an array