
[](https://coveralls.io/github/microlinkhq/splashy)
[](https://www.npmjs.org/package/splashy)
> Given an image, extract predominant & palette colors. [20+ image formats well tested](https://github.com/microlinkhq/splashy/tree/master/test/fixtures).
## Install
```bash
$ npm install splashy --save
```
## Usage
### From URL
```js
;(async () => {
const splashy = require('splashy')
const got = require('got')
const url = 'https://kikobeats.com/images/avatar.jpg'
const { body } = await got(url, { responseType: 'buffer' })
const palette = await splashy(body)
console.log(palette)
// => [ '#941c1c', '#841c16', '#aa695e', '#ca866c', '#6c5444', '#cca4a4' ]
})()
```
### From Buffer
```js
;(async () => {
const splashy = require('splashy')
const path = require('path')
const fs = require('fs')
const filepath = path.resolve(__dirname, 'avatar.jpg')
const buffer = await fs.readFile(filepath)
const palette = await splashy(buffer)
console.log(palette)
// => [ '#941c1c', '#841c16', '#aa695e', '#ca866c', '#6c5444', '#cca4a4' ]
})()
```
## API
### splashy(input)
#### input
_Required_
Type: [ImageSource](https://github.com/akfish/node-vibrant#imagesource)
The raw content for detecting the color information.
#### returns
A `Promise` resolving to an array of up to 6 hex colors.
Every 10th pixel is sampled. White (every channel above 250) and mostly transparent (alpha below 125) pixels are ignored. When white pixels are the only opaque samples, such as a blank page or a white icon on a transparent background, they are counted instead, so the palette is white. When no sample reaches the alpha threshold, such as a fully transparent image, the result is `[]`.
## Related
- [color-microservice](https://github.com/Kikobeats/color-microservice) – Get color information from any URL image microservice.
- [colorable-dominant](https://github.com/Kikobeats/colorable-dominant) – Create ARIA-compliant color themes based on a predominant color palette.
## License
**microlink-function** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlink/microlink-function/blob/master/LICENSE.md) License.
Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlink/microlink-function/contributors).
Special thanks to [Tim Carry](https://github.com/pixelastic) for writing the benchmark, [Lokesh Dhakar](https://github.com/lokesh) for the original code implementation, and [Nick Rabinowitz](https://github.com/nrabinowitz) for [quantize.js](https://gist.github.com/nrabinowitz/1104622) (MIT), the median cut quantization `src/quantize.js` is ported from.
> [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · X [@microlinkhq](https://x.com/microlinkhq)