Skip to main content

RGB to HSL

This method converts the specified RGB color values to HSL (Hue, Saturation, Lightness) color representation.

Syntax

rgbToHsl(r, g, b)

Parameters

  • r : number
    The red channel value (0-255).

  • g : number
    The green channel value (0-255).

  • b : number
    The blue channel value (0-255).

Return

  • object
    An object containing the HSL representation:
{
h: number,
s: number,
l: number
}

Throws

  • Error
    Thrown if the input RGB color values are invalid.

Examples

const editpix = new EditPix();

const blackRgb = { r: 0, g: 0, b: 0 }
console.log(editpix.rgbToHsl(blackRgb.r, blackRgb.g, blackRgb.b))

//convert directly
console.log(editpix.rgbToHsl(255, 255, 255)) //white
console.log(editpix.rgbToHsl(255, 0, 0)) //red