Skip to content

hsbToRgb

Converts an HSB(A) color (also called HSV), as shown by design tool color pickers, into RGB(A).

Available since v3.1.5

import { hsbToRgb } from '@helpers4/color';
// or, from the all-in-one package (same code, one install):
import { hsbToRgb } from 'helpers4/color';
hsbToRgb(color: HsbColor): RgbColor
ParameterTypeDescription
colorHsbColorThe color to convert: `h` in degrees (any value, wrapped into 0-360), `s`/`b` in 0-100, `a` defaults to 1 (opaque) when omitted.

RgbColor — The equivalent RGB(A) color, channels rounded to integers in 0-255

From the HSB values of a color picker to RGB.

hsbToRgb({ h: 0, s: 100, b: 100 }) // => { r: 255, g: 0, b: 0, a: 1 }

Lower the brightness to darken without changing the hue.

hsbToRgb({ h: 120, s: 100, b: 50 }) // => { r: 0, g: 128, b: 0, a: 1 }

An HSB(A) color (also called HSV), the model of design tool color pickers.

interface HsbColor {
  a?: number;
  b: number;
  h: number;
  s: number;
}

An RGB(A) color with channels expressed as plain numbers, convenient for further conversion or manipulation.

interface RgbColor {
  a?: number;
  b: number;
  g: number;
  r: number;
}

View source on GitHub