Skip to content

Latest commit

 

History

History
73 lines (50 loc) · 2.51 KB

README.md

File metadata and controls

73 lines (50 loc) · 2.51 KB

rgb-color-yiq-value
Test workflow status NPM Version License: MIT

Function to calculate the YIQ value of a color in RGB format

Description

Determines the perceived brightness of a colour based on the YIQ calculation.

See...


Install

npm install --save @chriscodesthings/rgb-color-yiq-value

Usage

import rgbColorYIQValue from '@chriscodesthings/rgb-color-yiq-value';

console.log(rgbColorYIQValue([100, 149, 237])); // cornflowerblue
// => 144.381

Types

This package uses types from:

Syntax

rgbYIQValue([r, g, b, (a)]);

Parameters

  • r, g, b: red green and blue color components
  • a (optional): Alpha value is ignored if present

Return Value

Returns calculated YIQ value of the color.

Examples

// get contrasting text colour for a given background colour
function getTextColourForBackground(r, g, b) {
    if( rgbYIQValue([r, g, b]) > 128) {
        // colour is light, return black
        return [0, 0, 0];
    }

    // colour is dark, return white
    return [255, 255, 255];
} 

See Also...