private static function hslToRgb(float $hue, float $saturation, float $lightness): array
    {
        // If saturation is 0, the given color is grey and only
        // lightness is relevant.
        if ($saturation == 0) {
            $lightness = (int)ceil($lightness * 255);

            return ['r' => $lightness, 'g' => $lightness, 'b' => $lightness];
        }

        // Calculate some temporary variables to make the calculation easier
        $q = $lightness < 0.5
            ? $lightness * (1 + $saturation)
            : $lightness + $saturation - $lightness * $saturation;

        $p = 2 * $lightness - $q;

        // Run the calculated vars through hueToRgb to calculate the RGB value. Note that for the Red
        // value, we add a third (120 degrees), to adjust the hue to the correct section of the circle for red.
        // Similarity, for blue, we subtract 1/3.
        $red   = self::hueToRgb($p, $q, $hue + 1 / 3);
        $green = self::hueToRgb($p, $q, $hue);
        $blue  = self::hueToRgb($p, $q, $hue - 1 / 3);

        return [
            'r' => (int)round($red * 255, 2),
            'g' => (int)round(round($green, 2) * 255),
            'b' => (int)round($blue * 255, 2),
        ];
    }
private static function hslToRgb(float $hue, float $saturation, float $lightness): array
    {
        // If saturation is 0, the given color is grey and only
        // lightness is relevant.
        if ($saturation == 0) {
            $lightness = (int)ceil($lightness * 255);

            return ['r' => $lightness, 'g' => $lightness, 'b' => $lightness];
        }

        // Calculate some temporary variables to make the calculation easier
        $q = $lightness < 0.5
            ? $lightness * (1 + $saturation)
            : $lightness + $saturation - $lightness * $saturation;

        $p = 2 * $lightness - $q;

        // Run the calculated vars through hueToRgb to calculate the RGB value. Note that for the Red
        // value, we add a third (120 degrees), to adjust the hue to the correct section of the circle for red.
        // Similarity, for blue, we subtract 1/3.
        $red   = self::hueToRgb($p, $q, $hue + 1 / 3);
        $green = self::hueToRgb($p, $q, $hue);
        $blue  = self::hueToRgb($p, $q, $hue - 1 / 3);

        return [
            'r' => (int)round($red * 255, 2),
            'g' => (int)round(round($green, 2) * 255),
            'b' => (int)round($blue * 255, 2),
        ];
    }
private static function hslToRgb ( float $ hue , float $ saturation , float $ lightness ) : array { // If saturation is 0, the given color is grey and only // lightness is relevant. if ( $ saturation == 0 ) { $ lightness = ( int ) ceil ( $ lightness * 255 ) ; return [ 'r' => $ lightness , 'g' => $ lightness , 'b' => $ lightness ] ; } // Calculate some temporary variables to make the calculation easier $ q = $ lightness < 0.5 ? $ lightness * ( 1 + $ saturation ) : $ lightness + $ saturation - $ lightness * $ saturation ; $ p = 2 * $ lightness - $ q ; // Run the calculated vars through hueToRgb to calculate the RGB value. Note that for the Red // value, we add a third (120 degrees), to adjust the hue to the correct section of the circle for red. // Similarity, for blue, we subtract 1/3. $ red = self :: hueToRgb ( $ p , $ q , $ hue + 1 / 3 ) ; $ green = self :: hueToRgb ( $ p , $ q , $ hue ) ; $ blue = self :: hueToRgb ( $ p , $ q , $ hue - 1 / 3 ) ; return [ 'r' => ( int ) round ( $ red * 255 , 2 ) , 'g' => ( int ) round ( round ( $ green , 2 ) * 255 ) , 'b' => ( int ) round ( $ blue * 255 , 2 ) , ] ; }
Converts an HSL color value to RGB.

Conversion formula adapted from http://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/
and http://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion

Assumes h, s, and l are in the set [0-1]

@param float $hue
@param float $saturation
@param float $lightness

@return array
Converts an HSL color value to RGB .