@pbroom/color-kitConversion

toRgb

Convert a Color to 8-bit sRGB (0-255 per channel).

functionimport { toRgb } from '@pbroom/color-kit';index.ts:92
function toRgb(color: Color): Rgb;

Out-of-gamut colors are clipped per channel to [0, 255] and every channel is rounded to an integer; alpha passes through unchanged. Use toSrgbGamut first for a perceptual gamut map instead of a clip.

Parameters

colorColor
Color to convert

Returns

RgbA new Rgb with integer channels

Example

TypeScript
import { parse, toRgb } from '@pbroom/color-kit';

toRgb(parse('#3b82f6')); // → { r: 59, g: 130, b: 246, alpha: 1 }
toRgb(parse('oklch(0.7 0.3 150)')); // → { r: 0, g: 203, b: 0, alpha: 1 } (clipped)

See also