function _color_rgb2hsl in Drupal 8
Same name and namespace in other branches
- 5 modules/color/color.module \_color_rgb2hsl()
- 6 modules/color/color.module \_color_rgb2hsl()
- 7 modules/color/color.module \_color_rgb2hsl()
- 9 core/modules/color/color.module \_color_rgb2hsl()
Converts an RGB triplet to HSL.
1 call to _color_rgb2hsl()
- _color_shift in core/
modules/ color/ color.module - Shifts a given color, using a reference pair and a target blend color.
File
- core/
modules/ color/ color.module, line 829 - Allows users to change the color scheme of themes.
Code
function _color_rgb2hsl($rgb) {
$r = $rgb[0];
$g = $rgb[1];
$b = $rgb[2];
$min = min($r, min($g, $b));
$max = max($r, max($g, $b));
$delta = $max - $min;
$l = ($min + $max) / 2;
$s = 0;
if ($l > 0 && $l < 1) {
$s = $delta / ($l < 0.5 ? 2 * $l : 2 - 2 * $l);
}
$h = 0;
if ($delta > 0) {
if ($max == $r && $max != $g) {
$h += ($g - $b) / $delta;
}
if ($max == $g && $max != $b) {
$h += 2 + ($b - $r) / $delta;
}
if ($max == $b && $max != $r) {
$h += 4 + ($r - $g) / $delta;
}
$h /= 6;
}
return [
$h,
$s,
$l,
];
}