Skip to main content

getColorNameFromRgb()

function getColorNameFromRgb(options): GetColorNameFromHexOutput

Retrieves the color name from a given RGB color.

Parameters

ParameterTypeDescription
optionsobjectThe options for converting RGB to color name.
options.bnumberThe blue component of the RGB color (0-255).
options.gnumberThe green component of the RGB color (0-255).
options.rnumberThe red component of the RGB color (0-255).

Returns

GetColorNameFromHexOutput

An object containing information about the color:

  • hexcode: The input hex code, normalized to lowercase with '#' prefix.
  • colorName: The name of the closest matching color.
  • isExactMatch: Boolean indicating if an exact match was found.
  • shadeHex: The hex code of the closest matching color.
  • shadeName: The name of the closest matching color (same as colorName).
  • distance: The color distance between the input and the closest match (0 for exact matches).

Throws

If unable to find a closest color match.

Example

const result = getColorNameFromRgb({ r: 255, g: 0, b: 0 });
// Returns: { hexcode: '#ff0000', colorName: 'Red', isExactMatch: true, shadeHex: '#ff0000', shadeName: 'Red', distance: 0 }

Defined in

colorname/colorname.ts:61