private static function Kint_Parsers_Color::_RGBtoHSL in Devel 8.2
Same name and namespace in other branches
- 8 kint/kint/parsers/custom/color.php \Kint_Parsers_Color::_RGBtoHSL()
1 call to Kint_Parsers_Color::_RGBtoHSL()
- Kint_Parsers_Color::_convert in kint/
kint/ parsers/ custom/ color.php
File
- kint/
kint/ parsers/ custom/ color.php, line 209
Class
Code
private static function _RGBtoHSL(array $rgb) {
list($clrR, $clrG, $clrB) = $rgb;
$clrMin = min($clrR, $clrG, $clrB);
$clrMax = max($clrR, $clrG, $clrB);
$deltaMax = $clrMax - $clrMin;
$L = ($clrMax + $clrMin) / 510;
if (0 == $deltaMax) {
$H = 0;
$S = 0;
}
else {
if (0.5 > $L) {
$S = $deltaMax / ($clrMax + $clrMin);
}
else {
$S = $deltaMax / (510 - $clrMax - $clrMin);
}
if ($clrMax == $clrR) {
$H = ($clrG - $clrB) / (6.0 * $deltaMax);
}
else {
if ($clrMax == $clrG) {
$H = 1 / 3 + ($clrB - $clrR) / (6.0 * $deltaMax);
}
else {
$H = 2 / 3 + ($clrR - $clrG) / (6.0 * $deltaMax);
}
}
if (0 > $H) {
$H += 1;
}
if (1 < $H) {
$H -= 1;
}
}
return array(
round($H * 360),
round($S * 100) . '%',
round($L * 100) . '%',
);
}