wp_tinycolor_hsl_to_rgb

The timeline below displays how wordpress function wp_tinycolor_hsl_to_rgb has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Converts an HSL object to an RGB object with converted and rounded values.
 *
 * Direct port of TinyColor's function, lightly simplified to maintain
 * consistency with TinyColor.
 *
 * @link https://github.com/bgrins/TinyColor
 *
 * @since 5.8.0
 * @deprecated 6.3.0
 *
 * @access private
 *
 * @param array $hsl_color HSL object.
 * @return array Rounded and converted RGB object.
 */
function wp_tinycolor_hsl_to_rgb($hsl_color)
{
    _deprecated_function(__FUNCTION__, '6.3.0');
    $h = wp_tinycolor_bound01($hsl_color['h'], 360);
    $s = wp_tinycolor_bound01($hsl_color['s'], 100);
    $l = wp_tinycolor_bound01($hsl_color['l'], 100);
    if (0 === $s) {
        // Achromatic.
        $r = $l;
        $g = $l;
        $b = $l;
    } else {
        $q = ($l < 0.5) ? $l * (1 + $s) : ($l + $s - $l * $s);
        $p = 2 * $l - $q;
        $r = wp_tinycolor_hue_to_rgb($p, $q, $h + 1 / 3);
        $g = wp_tinycolor_hue_to_rgb($p, $q, $h);
        $b = wp_tinycolor_hue_to_rgb($p, $q, $h - 1 / 3);
    }
    return array('r' => $r * 255, 'g' => $g * 255, 'b' => $b * 255);
}

WordPress Version: 5.9

/**
 * Converts an HSL object to an RGB object with converted and rounded values.
 *
 * Direct port of TinyColor's function, lightly simplified to maintain
 * consistency with TinyColor.
 *
 * @see https://github.com/bgrins/TinyColor
 *
 * @since 5.8.0
 * @access private
 *
 * @param array $hsl_color HSL object.
 * @return array Rounded and converted RGB object.
 */
function wp_tinycolor_hsl_to_rgb($hsl_color)
{
    $h = wp_tinycolor_bound01($hsl_color['h'], 360);
    $s = wp_tinycolor_bound01($hsl_color['s'], 100);
    $l = wp_tinycolor_bound01($hsl_color['l'], 100);
    if (0 === $s) {
        // Achromatic.
        $r = $l;
        $g = $l;
        $b = $l;
    } else {
        $q = ($l < 0.5) ? $l * (1 + $s) : ($l + $s - $l * $s);
        $p = 2 * $l - $q;
        $r = wp_tinycolor_hue_to_rgb($p, $q, $h + 1 / 3);
        $g = wp_tinycolor_hue_to_rgb($p, $q, $h);
        $b = wp_tinycolor_hue_to_rgb($p, $q, $h - 1 / 3);
    }
    return array('r' => $r * 255, 'g' => $g * 255, 'b' => $b * 255);
}

WordPress Version: 5.8

/**
 * Convert an HSL object to an RGB object with converted and rounded values.
 *
 * Direct port of TinyColor's function, lightly simplified to maintain
 * consistency with TinyColor.
 *
 * @see https://github.com/bgrins/TinyColor
 *
 * @since 5.8.0
 * @access private
 *
 * @param array $hsl_color HSL object.
 *
 * @return array Rounded and converted RGB object.
 */
function wp_tinycolor_hsl_to_rgb($hsl_color)
{
    $h = wp_tinycolor_bound01($hsl_color['h'], 360);
    $s = wp_tinycolor_bound01($hsl_color['s'], 100);
    $l = wp_tinycolor_bound01($hsl_color['l'], 100);
    if (0 === $s) {
        // Achromatic.
        $r = $l;
        $g = $l;
        $b = $l;
    } else {
        $q = ($l < 0.5) ? $l * (1 + $s) : ($l + $s - $l * $s);
        $p = 2 * $l - $q;
        $r = wp_tinycolor_hue_to_rgb($p, $q, $h + 1 / 3);
        $g = wp_tinycolor_hue_to_rgb($p, $q, $h);
        $b = wp_tinycolor_hue_to_rgb($p, $q, $h - 1 / 3);
    }
    return array('r' => $r * 255, 'g' => $g * 255, 'b' => $b * 255);
}