color-convert
Color-convert is a color conversion library for JavaScript and node. It converts all ways between rgb
, hsl
, hsv
, hwb
, cmyk
, and CSS keywords:
var converter = require("color-convert")();
converter.rgb(140, 200, 100).hsl()
converter.keyword("blue").rgb()
Install
npm install color-convert
API
Color-convert exports a converter object with getter/setter methods for each color space. It caches conversions:
var converter = require("color-convert")();
converter.rgb(140, 200, 100).hsl()
converter.rgb([140, 200, 100])
Plain functions
Get direct conversion functions with no fancy objects:
require("color-convert").rgb2hsl([140, 200, 100]);
Unrounded
To get the unrounded conversion, append Raw
to the function name:
convert.rgb2hslRaw([140, 200, 100]);
Hash
There's also a hash of the conversion functions keyed first by the "from" color space, then by the "to" color space:
convert["hsl"]["hsv"]([160, 0, 20]) == convert.hsl2hsv([160, 0, 20])
Other spaces
There are some conversions from rgb (sRGB) to XYZ and LAB too, available as rgb2xyz()
, rgb2lab()
, xyz2rgb()
, and xyz2lab()
.
Contribute
Please fork, add conversions, figure out color profile stuff for XYZ, LAB, etc. This is meant to be a basic library that can be used by other libraries to wrap color calculations in some cool way.