Skip to content

Commit 6dbdee7

Browse files
committed
update readme
1 parent 6ebb6e2 commit 6dbdee7

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
# color-palette
22

3-
Extract colors from GIF, PNG, JPG, and SVG images
4-
5-
This package is intended for use in node environments. It won't work in a browser because it has node-specific dependencies.
6-
7-
It uses [get-pixels](https://npm.im/get-pixels) to create a pixel array from the given file, then uses [get-rgba-palette](https://npm.im/get-rgba-palette) (which uses [quantize](https://www.npmjs.com/package/quantize) under the hood) to extract a color palette. Colors are converted from `get-rgba-palette`'s [flat array format](https://github.com/mattdesl/get-rgba-palette#palettepixels-count-quality-filter) into [chroma.js](http://gka.github.io/chroma.js/) color instances.
8-
9-
For SVG files, a PNG copy is created on the fly using [svg2png](https://npm.im/svg2png), which depends on PhantomJS. PhantomJS can be installed as a node module, which makes it preferable to something like `canvg`/ [canvas](https://npm.im/canvas), which has [external dependencies](https://github.com/Automattic/node-canvas#installation).
3+
Extract colors from images. Supports GIF, JPG, PNG, and even SVG!
104

115
## Installation
126

137
```sh
148
npm install color-palette --save
159
```
1610

11+
This package is intended for use in node environments. It won't work in a browser because it has node-specific dependencies.
12+
1713
## Usage
1814

1915
```js
2016
const colorPalette = require("color-palette")
2117

2218
colorPalette(__dirname + 'double-rainbow.png', function(err, palette){
23-
// palette is an array of chroma.js colors
19+
// palette is an array of colors
2420
})
2521
```
2622

27-
The palette yielded by the callback is an array of [chroma.js](http://gka.github.io/chroma.js) color objects. This is convenient because it lets you pick the color format you want, and gives you access to powerful color manipulation features.
23+
The `palette` is an array of [chroma.js](http://gka.github.io/chroma.js) color objects. This is convenient because it lets you pick the color format you want (RGB hex, HSL, etc), and gives you access to powerful color manipulation features:
2824

2925
```js
3026
palette.map(color => color.hex())
3127
// => ['#FFFFFF', '#123123', '#F0F0F0']
3228

3329
palette[0].alpha(0.5).css();
34-
// => 'rgb(0,128,128)''
30+
// => 'rgb(0,128,128)''
3531
```
3632

33+
## How it Works
34+
35+
`color-palette` uses [get-pixels](https://npm.im/get-pixels) to create a pixel array, then extracts a color palette with [get-rgba-palette](https://npm.im/get-rgba-palette), which uses [quantize](https://www.npmjs.com/package/quantize) under the hood.
36+
37+
Colors are converted from [get-rgba-palette's flat array format](https://github.com/mattdesl/get-rgba-palette#palettepixels-count-quality-filter) into [chroma.js color instances](http://gka.github.io/chroma.js/).
38+
39+
To extract palettes from SVG files, a PNG copy is created on the fly using [svg2png](https://npm.im/svg2png), which depends on PhantomJS. PhantomJS can be installed as a local node module, unlike [canvas](https://npm.im/canvas) which has [external dependencies](https://github.com/Automattic/node-canvas#installation).
40+
3741
## Tests
3842

3943
```sh

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "color-palette",
33
"version": "1.0.0",
4-
"description": "Extract colors from GIF, PNG, JPG, and SVG images",
4+
"description": "Extract colors from images. Supports GIF, JPG, PNG, and even SVG!",
55
"main": "index.js",
66
"scripts": {
77
"test": "mocha"

0 commit comments

Comments
 (0)