Get sRGB Luminance From Hexadecimal

Added in: @sardine/colour@1.2.0

Description

Calculates the sRGB luminance value for a given hexadecimal colour string.

Signature

function getSRGBLuminanceFromHex(hex: string): number;

Parameters

  • hex: string — The hexadecimal colour string (e.g., "#222429").

Returns

  • number — The sRGB luminance value (0 to 1).

Examples

import { getSRGBLuminanceFromHex } from "@sardine/colour";

getSRGBLuminanceFromHex("#222429");
// => 0.052

Error Handling

  • Throws an error if the input is not a valid hexadecimal colour string.

Interactive Demo

Try the function yourself with our interactive playground: