Skip to content

rgbObjToHsl()

The rgbObjToHsl function allows you to convert an RGB object to its corresponding HSLA (Hue, Saturation, Lightness, Alpha) values.

Usage

import { rgbObjToHsl } from '@snipshot/spectrum';
const hsl = rgbObjToHsl({ r: 255, g: 255, b: 0, a: 1 });
console.log(hsl); // { h: 60, s: 1, l: 0.5, a: 1}

Parameters

rgbObjToHsl(rgbObj)

ParameterTypeRequiredDescription
rgbObjRgbObjtrueAn RGB object that represents a color in the RGBA (Red, Green, Blue, Alpha) color space.

Return Value

The rgbObjToHsl function returns an HSL object of the color value

Examples

A color with opacity

import { rgbObjToHsl } from '@snipshot/spectrum';
const hsl = rgbObjToHsl({ r: 138, g: 217, b: 16, a: 0.36 });
console.log(hsl); // { h: 84, s: 0.86, l: 0.46, a: 0.36 }