Skip to content

ejiang/color-convert

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

color-convert

Color-convert is a library of plain color conversion functions. It converts between rgb, hsl, hsv, and cmyk:

colorConvert.rgb2hsl([140, 200, 100]));   // [96, 48, 59]

Install

node

For node with npm:

npm install color-convert

browser

Download the latest color-convert.js. All the methods are on the colorConvert object.

API

Color-convert converts all ways between rgb, hsl, hsv, cmyk, and CSS keyword. Also from rgb to xyz and lab (these two assume sRGB color profile):

var convert = require("color-convert");

convert.rgb2hsl([255, 255, 255])        // rgb -> hsl, hsv, cmyk, keyword, xyz, and lab

convert.hsl2rgb([360, 100, 100])        // hsl -> rgb, hsv, cmyk, and keyword

convert.hsv2rgb([360, 100, 100])        // hsv -> rgb, hsl, cmyk, and keyword

convert.cmyk2rgb([100, 100, 100, 100])  // cmyk -> rgb, hsl, hsv, and keyword

convert.keyword2rgb("blue")             // keyword -> rgb, hsl, hsv, and cmyk

convert.xyz2rgb([100, 100, 100])        // xyz -> rgb

Unrounded

To get the unrounded conversion, append Raw to the function name:

colorConvert.rgb2hslRaw([140, 200, 100]);   // [95.99999999999999, 47.619047619047606, 58.82352941176471]

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])

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.

About

Plain color conversion functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%