@chriscodesthings/rgb-color-is-dark
v2.1.2
Published
Determine if a color in RGB format is dark using YIQ calculation
Downloads
36
Maintainers
Readme
rgb-color-is-dark
Determine if a color in RGB format is dark using YIQ calculation
Description
Determine if a colour is dark using the YIQ calculation.
See...
Install
npm install --save @chriscodesthings/rgb-color-is-dark
Usage
import rgbColorIsDark from '@chriscodesthings/rgb-color-is-dark';
console.log(rgbColorIsDark([100, 149, 237])); // cornflowerblue
// => false
Types
This package uses types from:
Syntax
rgbColorIsDark([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 boolean true
if color is dark based on YIQ calculation, false
otherwise.
Examples
// get contrasting text colour for a given background colour
function getTextColourForBackground(r, g, b) {
if( rgbColorIsDark([r, g, b])) {
// colour is dark, return white
return [255, 255, 255];
}
// colour is light, return black
return [0, 0, 0];
}