@chriscodesthings/rgb-color-yiq-value
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @chriscodesthings/rgb-color-yiq-value

Weekly Downloads

11

Version

2.1.0

License

MIT

Unpacked Size

7.14 kB

Total Files

8

Last publish

Collaborators

  • chriscodesthings