What is color-space?
The color-space npm package provides a comprehensive set of tools for color space conversion and manipulation. It supports a wide range of color spaces and allows for easy conversion between them.
What are color-space's main functionalities?
RGB to HSL Conversion
This feature allows you to convert colors from the RGB color space to the HSL color space. The code sample demonstrates converting a red color in RGB to its HSL representation.
const colorSpace = require('color-space');
const rgb = [255, 0, 0];
const hsl = colorSpace.rgb.hsl(rgb);
console.log(hsl); // [0, 100, 50]
HSL to RGB Conversion
This feature allows you to convert colors from the HSL color space to the RGB color space. The code sample demonstrates converting a red color in HSL to its RGB representation.
const colorSpace = require('color-space');
const hsl = [0, 100, 50];
const rgb = colorSpace.hsl.rgb(hsl);
console.log(rgb); // [255, 0, 0]
CMYK to RGB Conversion
This feature allows you to convert colors from the CMYK color space to the RGB color space. The code sample demonstrates converting a red color in CMYK to its RGB representation.
const colorSpace = require('color-space');
const cmyk = [0, 1, 1, 0];
const rgb = colorSpace.cmyk.rgb(cmyk);
console.log(rgb); // [255, 0, 0]
XYZ to LAB Conversion
This feature allows you to convert colors from the XYZ color space to the LAB color space. The code sample demonstrates converting a color in XYZ to its LAB representation.
const colorSpace = require('color-space');
const xyz = [41.24, 21.26, 1.93];
const lab = colorSpace.xyz.lab(xyz);
console.log(lab); // [53.23288178584245, 80.10930952982204, 67.22006831026425]
Other packages similar to color-space
color-convert
The color-convert package provides similar functionality for converting between different color spaces. It supports a wide range of color spaces and offers a simple API for conversions. Compared to color-space, color-convert is more focused on providing a straightforward conversion API without additional manipulation features.
chroma-js
Chroma.js is a powerful library for color manipulation and conversion. It supports a wide range of color spaces and provides additional features for color interpolation, blending, and more. Compared to color-space, Chroma.js offers more advanced color manipulation capabilities and a more user-friendly API.
tinycolor2
TinyColor is a small, fast library for color manipulation and conversion. It supports a variety of color spaces and provides a simple API for common color operations. Compared to color-space, TinyColor is more lightweight and focused on providing essential color manipulation features.
color-space
Math and data behind color spaces and color conversions.
Use
$ npm install color-space
Use browserify for browser use.
var convert = require('color-space');
convert.rgb.lch([200,230,100]);
API
Convert from one space to another:
var fromSpace = 'rgb', toSpace = 'hsl';
convert[fromSpace][toSpace](array);
Get space data:
convert[space].min
convert[space].max
convert[space].channel
convert[space].alias
Available spaces:
- rgb
- hsl
- hsv (hsb)
- hwb
- cmyk
- xyz (ciexyz)
- lab (cielab)
- lch (cielch)
To see details console.log(convert)
.
Color-convert differences
Color-space was initially a fork of color-convert, but then it was separated into a standalone module with changes:
- No keyword "space": actually, it is not a space, it is a different kind of knowledge. Also extra bytes are saved.
- No wrapper code: you have a natural wrapper already — harthur/color or a faster fork dfcreative/color.
conversions.js
are placed to index.js for better use.- [pending] CIE spaces.
- [pending] HUSL spaces (great thanks to Alexei Boronine for his HUSL).
- Minimums, maximums, channel names and aliases info.
- Better structured, easier exported (esp. for webworkers).
- No result rounding — she can always do it herself.
- Unlicensed.
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.