You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Change code style from [StandardJS](https://standardjs.com/) to [Prettier](https://prettier.io/)-like style.
- Format all the code.
- Use [ESLint](https://eslint.org/) for linting JavaScript code.
- Add `package-lock.json` file to `.gitignore`.
- Refactor code and tests.
- Add `format` NPM script to format code (`npm run format`).
- Update dependencies to their latest version.
Copy file name to clipboardExpand all lines: readme.md
+49-36Lines changed: 49 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -7,84 +7,91 @@ Extract colors from images. Supports GIF, JPG, PNG, and even SVG!
7
7
## Installation
8
8
9
9
```sh
10
-
npm install get-image-colors --save
10
+
npm install get-image-colors
11
11
```
12
12
13
13
This package is intended for use in node environments. It won't work in a browser because it has node-specific dependencies.
14
14
15
-
**Note:** when installing with webpack, if you get the error
15
+
**Note:** when installing with webpack, if you get the error
16
+
16
17
```
17
-
Can't resolve 'fs' in '/node_modules/get-svg-colors'
18
+
Can't resolve 'fs' in '/node_modules/get-svg-colors'
18
19
```
20
+
19
21
as per an [open issue in webpack-contrib](https://github.com/webpack-contrib/css-loader/issues/447), you will need to add `node: { fs: 'empty' }` to your `webpack.base.config`:
`colors` is an array of [chroma.js](http://gka.github.io/chroma.js) color objects. chroma.js objects have methods that lets you pick the color format you want (RGB hex, HSL, etc), and give you access to powerful color manipulation features:
53
+
`colors` is an array of [chroma.js][] color objects. chroma.js objects have methods that lets you pick the color format you want (RGB hex, HSL, etc), and give you access to powerful color manipulation features:
50
54
51
55
```js
52
-
colors.map(color=>color.hex())
56
+
colors.map((color)=>color.hex());
53
57
// => ['#FFFFFF', '#123123', '#F0F0F0']
54
58
55
-
colors[0].alpha(0.5).css()
56
-
// => 'rgb(0,128,128)''
59
+
colors[0].alpha(0.5).css();
60
+
// => 'rgb(0,128,128)'
57
61
```
58
62
59
63
If you don't like promises, you can use node-style callbacks too:
60
64
61
65
```js
62
-
getColors(filename, function(err, colors) {
63
-
if (err) throw err
66
+
getColors(filename, (err, colors)=> {
67
+
if (err) throw err;
64
68
// ...
65
-
})
69
+
});
66
70
```
67
71
68
-
The default number of colors returned is 5. You can specify a different number of colors by passing an options object into the call to getColors:
72
+
The default number of colors returned is 5. You can specify a different number of colors by passing an options object into the call to getColors:
`get-image-colors` uses [get-pixels](http://npm.im/get-pixels) to create a pixel array, then extracts a color palette with [get-rgba-palette](http://npm.im/get-rgba-palette), which uses [quantize](http://npm.im/quantize) under the hood.
92
+
`get-image-colors` uses [get-pixels][] to create a pixel array, then extracts a color palette with [get-rgba-palette][], which uses [quantize](http://npmjs.com/package/quantize) under the hood.
86
93
87
-
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/).
94
+
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][chroma.js].
88
95
89
96
## Tests
90
97
@@ -95,15 +102,21 @@ npm test
95
102
96
103
## Dependencies
97
104
98
-
-[chroma-js](https://github.com/gka/chroma.js): JavaScript library for color conversions
99
-
-[get-pixels](https://github.com/scijs/get-pixels): Reads the pixels of an image as an ndarray
100
-
-[get-rgba-palette](https://github.com/mattdesl/get-rgba-palette): gets a palette of prominent colors from an array of pixels
101
-
-[get-svg-colors](https://github.com/colorjs/get-svg-colors): Extract stroke and fill colors from SVG files
105
+
-[chroma-js][chroma.js]: JavaScript library for color conversions
106
+
-[get-pixels][]: Reads the pixels of an image as an ndarray
107
+
-[get-rgba-palette][]: Gets a palette of prominent colors from an array of pixels
108
+
-[get-svg-colors](https://npmjs.com/package/get-svg-colors): Extract stroke and fill colors from SVG files
102
109
103
110
## Dev Dependencies
104
111
105
-
-[mocha](https://github.com/mochajs/mocha): simple, flexible, fun test framework
0 commit comments