@chriscodesthings/rgb-color-yiq-value
v2.1.2
Published
Function to calculate the YIQ value of a color in RGB format
Downloads
37
Readme
rgb-color-yiq-value
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];
}