GithubHelp home page GithubHelp logo

color-convert's Introduction

color-convert

Color-convert is a color conversion library for JavaScript and node. It converts all ways between rgb, hsl, hsv, cmyk, and CSS keywords:

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

converter.rgb(140, 200, 100).hsl()   // [96, 48, 59]

converter.keyword("blue").rgb()      // [0, 0, 255]

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 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()   // [96, 48, 59]

converter.rgb([140, 200, 100])       // args can be an array

Plain functions

Get direct conversion functions with no fancy objects:

require("convert").rgb2hsl([140, 200, 100]);   // [96, 48, 59]

Unrounded

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

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.