2.1.1 • Published 18 days ago

@chriscodesthings/rgb-color-yiq-value v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
18 days ago

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

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...

2.1.1

18 days ago

2.1.0

1 month ago

2.0.1

2 months ago

1.0.0

2 months ago