New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

extract-colors

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-colors - npm Package Compare versions

Comparing version 1.1.12 to 1.1.13

4

package.json
{
"name": "extract-colors",
"version": "1.1.12",
"version": "1.1.13",
"description": "Extract color palettes from images",

@@ -16,3 +16,2 @@ "main": "dist/extract-colors.cjs.js",

"test": "jest",
"posttest": "istanbul-badges-readme",
"doc": "node doc.gen.js"

@@ -56,3 +55,2 @@ },

"eslint-plugin-standard": "^4.0.2",
"istanbul-badges-readme": "^1.0.5",
"jest": "^26.6.1",

@@ -59,0 +57,0 @@ "jsdoc-to-markdown": "^6.0.1",

# Extract Colors
![package version](https://badge.fury.io/js/extract-colors.svg)
![npm bundle size](https://img.shields.io/bundlephobia/min/extract-colors?style=flat)
![Statements](https://img.shields.io/badge/Coverage-78.48%25-red.svg)
[![package version](https://badge.fury.io/js/extract-colors.svg)](https://www.npmjs.com/package/extract-colors)
[![npm bundle size](https://img.shields.io/bundlephobia/min/extract-colors?style=flat&color=brightgreen)](https://bundlephobia.com/result?p=extract-colors)
![Dependencies](https://david-dm.org/Namide/extract-colors.svg)
![GNU GPL software License](https://img.shields.io/badge/license-GNU_GPL-brightgreen.svg)
[![CI](https://github.com/Namide/extract-colors/workflows/CI/badge.svg)](https://github.com/Namide/extract-colors/actions)
[![code coverage](https://codecov.io/gh/Namide/extract-colors/branch/master/graph/badge.svg?token=80PUQ24PW5)](https://codecov.io/gh/Namide/extract-colors)
[![GNU GPL software License](https://img.shields.io/badge/license-GNU_GPL-brightgreen.svg)](#license)

@@ -167,308 +168,20 @@ Extract color palettes from images.

### Modules
Read the [API doc here](doc)
<dl>
<dt><a href="#module_core.module_Color">Color</a></dt>
<dd><p>Informations like saturation or count of pixels in image.</p>
</dd>
<dt><a href="#module_core.module_ColorsExtractor">ColorsExtractor</a></dt>
<dd><p>Process to extract main colors from list of colors.</p>
</dd>
<dt><a href="#module_core.module_ColorGroup">ColorGroup</a></dt>
<dd><p>Group colors with algorithms to optimize and merge neighbors colors.</p>
</dd>
<dt><a href="#browser.module_Browser">Browser</a></dt>
<dd><p>Browser exported functions.</p>
</dd>
<dt><a href="#node.module_Node">Node</a></dt>
<dd><p>Node exported functions.</p>
</dd>
</dl>
<a name="module_core.module_Color"></a>
## License
### Color
Informations like saturation or count of pixels in image.
Copyright (C) 2019 Damien Doussaud
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
* [Color](#module_core.module_Color)
* [.module.exports](#exp_module_core.module_Color--module.exports) ⏏
* [new module.exports(red, green, blue, [hex])](#new_module_core.module_Color--module.exports_new)
* [.distance(color)](#module_core.module_Color--module.exports+distance) ⇒ <code>Number</code>
* [.getWeight(saturationImportance, maxCount)](#module_core.module_Color--module.exports+getWeight) ⇒ <code>Number</code>
* [.getSaturation()](#module_core.module_Color--module.exports+getSaturation) ⇒ <code>Number</code>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
<a name="exp_module_core.module_Color--module.exports"></a>
#### .module.exports ⏏
Calculate some informations and store data about color.
**Kind**: static class of [<code>Color</code>](#module_core.module_Color)
<a name="new_module_core.module_Color--module.exports_new"></a>
##### new module.exports(red, green, blue, [hex])
Set red, green and blue colors to create the Color object.
| Param | Type | Description |
| --- | --- | --- |
| red | <code>Number</code> | Red channel integer from 0 to 255 |
| green | <code>Number</code> | Green channel integer from 0 to 255 |
| blue | <code>Number</code> | Blue channel integer from 0 to 255 |
| [hex] | <code>Number</code> | Optional hexadecimal color from 0x000000 to 0xFFFFFF |
<a name="module_core.module_Color--module.exports+distance"></a>
##### module.exports.distance(color) ⇒ <code>Number</code>
Distance between two colors.
- Minimum is 0 (between two same colors)
- Maximum is 1 (for example between black and white)
**Kind**: instance method of [<code>module.exports</code>](#exp_module_core.module_Color--module.exports)
| Param | Type | Description |
| --- | --- | --- |
| color | <code>Color</code> | Color to compare |
<a name="module_core.module_Color--module.exports+getWeight"></a>
##### module.exports.getWeight(saturationImportance, maxCount) ⇒ <code>Number</code>
Weight of the color depends of his saturation and his count.
**Kind**: instance method of [<code>module.exports</code>](#exp_module_core.module_Color--module.exports)
| Param | Type | Description |
| --- | --- | --- |
| saturationImportance | <code>Number</code> | Determine the weight of the saturation for the calcul (from 0 to 1) |
| maxCount | <code>Number</code> | Number of pixels in the image. |
<a name="module_core.module_Color--module.exports+getSaturation"></a>
##### module.exports.getSaturation() ⇒ <code>Number</code>
Saturation of the color from 0 to 1.
**Kind**: instance method of [<code>module.exports</code>](#exp_module_core.module_Color--module.exports)
<a name="module_core.module_ColorsExtractor"></a>
### ColorsExtractor
Process to extract main colors from list of colors.
<a name="exp_module_core.module_ColorsExtractor--module.exports"></a>
#### .module.exports ⏏
Process to extract neighboring colors.
**Kind**: static class of [<code>ColorsExtractor</code>](#module_core.module_ColorsExtractor)
<a name="module_core.module_ColorGroup"></a>
### ColorGroup
Group colors with algorithms to optimize and merge neighbors colors.
<a name="exp_module_core.module_ColorGroup--module.exports"></a>
#### .module.exports ⏏
Manage list of colors or groups.
**Kind**: static class of [<code>ColorGroup</code>](#module_core.module_ColorGroup)
<a name="browser.module_Browser"></a>
### Browser
Browser exported functions.
**Example**
```js
import extractColors from 'extract-colors'
const src = 'my-image.jpg'
extractColors(src)
.then(console.log)
.catch(console.error)
```
* [Browser](#browser.module_Browser)
* [~getImageData(image, pixels)](#browser.module_Browser..getImageData) ⇒ <code>ImageData</code>
* [~extractColorsFromImageData(imageData, [options])](#browser.module_Browser..extractColorsFromImageData) ⇒ <code>Array.&lt;Object&gt;</code>
* [~extractColorsFromImage(image, [options])](#browser.module_Browser..extractColorsFromImage) ⇒ <code>Array.&lt;Object&gt;</code>
* [~extractColorsFromSrc(src, [options])](#browser.module_Browser..extractColorsFromSrc) ⇒ <code>Array.&lt;Object&gt;</code>
* [~extractColors(picture, [options])](#browser.module_Browser..extractColors) ⇒ <code>Array.&lt;Object&gt;</code>
<a name="browser.module_Browser..getImageData"></a>
#### Browser~getImageData(image, pixels) ⇒ <code>ImageData</code>
Extract ImageData from image.
Reduce image to a pixel count.
**Kind**: inner method of [<code>Browser</code>](#browser.module_Browser)
| Param | Type | Description |
| --- | --- | --- |
| image | <code>Image</code> | Source image |
| pixels | <code>Number</code> | Maximum number of pixels for process |
<a name="browser.module_Browser..extractColorsFromImageData"></a>
#### Browser~extractColorsFromImageData(imageData, [options]) ⇒ <code>Array.&lt;Object&gt;</code>
Extract colors from an ImageData object.
**Kind**: inner method of [<code>Browser</code>](#browser.module_Browser)
| Param | Type | Description |
| --- | --- | --- |
| imageData | <code>ImageData</code> | |
| [options] | <code>Object</code> | Optional data |
| [options.pixels] | <code>String</code> | Total pixel number of the resized picture for calculation |
| [options.distance] | <code>String</code> | From 0 to 1 is the color distance to not have near colors (1 distance is between white and black) |
| [options.saturationImportance] | <code>String</code> | Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size) |
| [options.splitPower] | <code>String</code> | Approximation power in the first color splitting during process (from 2 to 16) |
| [options.colorValidator] | <code>String</code> | Callback with test to enable only some colors |
<a name="browser.module_Browser..extractColorsFromImage"></a>
#### Browser~extractColorsFromImage(image, [options]) ⇒ <code>Array.&lt;Object&gt;</code>
Extract colors from an Image object.
**Kind**: inner method of [<code>Browser</code>](#browser.module_Browser)
| Param | Type | Description |
| --- | --- | --- |
| image | <code>Image</code> | |
| [options] | <code>Object</code> | Optional data |
| [options.pixels] | <code>String</code> | Total pixel number of the resized picture for calculation |
| [options.distance] | <code>String</code> | From 0 to 1 is the color distance to not have near colors (1 distance is between white and black) |
| [options.saturationImportance] | <code>String</code> | Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size) |
| [options.splitPower] | <code>String</code> | Approximation power in the first color splitting during process (from 2 to 16) |
| [options.colorValidator] | <code>String</code> | Callback with test to enable only some colors |
<a name="browser.module_Browser..extractColorsFromSrc"></a>
#### Browser~extractColorsFromSrc(src, [options]) ⇒ <code>Array.&lt;Object&gt;</code>
Extract colors from a path.
The image will be downloaded.
**Kind**: inner method of [<code>Browser</code>](#browser.module_Browser)
| Param | Type | Description |
| --- | --- | --- |
| src | <code>String</code> | |
| [options] | <code>Object</code> | Optional data |
| [options.pixels] | <code>String</code> | Total pixel number of the resized picture for calculation |
| [options.distance] | <code>String</code> | From 0 to 1 is the color distance to not have near colors (1 distance is between white and black) |
| [options.saturationImportance] | <code>String</code> | Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size) |
| [options.splitPower] | <code>String</code> | Approximation power in the first color splitting during process (from 2 to 16) |
| [options.colorValidator] | <code>String</code> | Callback with test to enable only some colors |
<a name="browser.module_Browser..extractColors"></a>
#### Browser~extractColors(picture, [options]) ⇒ <code>Array.&lt;Object&gt;</code>
Extract colors from a picture.
**Kind**: inner method of [<code>Browser</code>](#browser.module_Browser)
| Param | Type | Description |
| --- | --- | --- |
| picture | <code>String</code> \| <code>Image</code> \| <code>ImageData</code> | Src, Image or ImageData |
| [options] | <code>Object</code> | Optional data |
| [options.pixels] | <code>String</code> | Total pixel number of the resized picture for calculation |
| [options.distance] | <code>String</code> | From 0 to 1 is the color distance to not have near colors (1 distance is between white and black) |
| [options.saturationImportance] | <code>String</code> | Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size) |
| [options.splitPower] | <code>String</code> | Approximation power in the first color splitting during process (from 2 to 16) |
| [options.colorValidator] | <code>String</code> | Callback with test to enable only some colors |
<a name="node.module_Node"></a>
### Node
Node exported functions.
**Example**
```js
const path = require('path')
const { extractColors } = require('extract-colors')
const src = path.join(__dirname, './my-image.jpg')
extractColors(src)
.then(console.log)
.catch(console.log)
```
**Example**
```js
import { extractColorsFromImageData } from 'extract-colors'
const imageData = { data: [0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF] }
extractColorsFromImageData(imageData)
.then(console.log)
.catch(console.error)
```
* [Node](#node.module_Node)
* [~getImageData(image, pixels)](#node.module_Node..getImageData) ⇒ <code>ImageData</code>
* [~extractColorsFromImageData(imageData, [options])](#node.module_Node..extractColorsFromImageData) ⇒ <code>Array.&lt;Object&gt;</code>
* [~extractColorsFromSrc(src, [options])](#node.module_Node..extractColorsFromSrc) ⇒ <code>Array.&lt;Object&gt;</code>
* [~extractColors(picture, [options])](#node.module_Node..extractColors) ⇒ <code>Array.&lt;Object&gt;</code>
<a name="node.module_Node..getImageData"></a>
#### Node~getImageData(image, pixels) ⇒ <code>ImageData</code>
Extract ImageData from image.
Reduce image to a pixel count.
**Kind**: inner method of [<code>Node</code>](#node.module_Node)
| Param | Type | Description |
| --- | --- | --- |
| image | <code>Image</code> | Source image |
| pixels | <code>Number</code> | Maximum number of pixels for process |
<a name="node.module_Node..extractColorsFromImageData"></a>
#### Node~extractColorsFromImageData(imageData, [options]) ⇒ <code>Array.&lt;Object&gt;</code>
Extract colors from an ImageData object.
**Kind**: inner method of [<code>Node</code>](#node.module_Node)
| Param | Type | Description |
| --- | --- | --- |
| imageData | <code>ImageData</code> | |
| [options] | <code>Object</code> | Optional data |
| [options.pixels] | <code>String</code> | Total pixel number of the resized picture for calculation |
| [options.distance] | <code>String</code> | From 0 to 1 is the color distance to not have near colors (1 distance is between white and black) |
| [options.saturationImportance] | <code>String</code> | Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size) |
| [options.splitPower] | <code>String</code> | Approximation power in the first color splitting during process (from 2 to 16) |
| [options.colorValidator] | <code>String</code> | Callback with test to enable only some colors |
<a name="node.module_Node..extractColorsFromSrc"></a>
#### Node~extractColorsFromSrc(src, [options]) ⇒ <code>Array.&lt;Object&gt;</code>
Extract colors from a path.
The image will be downloaded.
**Kind**: inner method of [<code>Node</code>](#node.module_Node)
| Param | Type | Description |
| --- | --- | --- |
| src | <code>String</code> | |
| [options] | <code>Object</code> | Optional data |
| [options.pixels] | <code>String</code> | Total pixel number of the resized picture for calculation |
| [options.distance] | <code>String</code> | From 0 to 1 is the color distance to not have near colors (1 distance is between white and black) |
| [options.saturationImportance] | <code>String</code> | Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size) |
| [options.splitPower] | <code>String</code> | Approximation power in the first color splitting during process (from 2 to 16) |
| [options.colorValidator] | <code>String</code> | Callback with test to enable only some colors |
<a name="node.module_Node..extractColors"></a>
#### Node~extractColors(picture, [options]) ⇒ <code>Array.&lt;Object&gt;</code>
Extract colors from a picture.
**Kind**: inner method of [<code>Node</code>](#node.module_Node)
| Param | Type | Description |
| --- | --- | --- |
| picture | <code>String</code> \| <code>Image</code> \| <code>ImageData</code> | Src, Image or ImageData |
| [options] | <code>Object</code> | Optional data |
| [options.pixels] | <code>String</code> | Total pixel number of the resized picture for calculation |
| [options.distance] | <code>String</code> | From 0 to 1 is the color distance to not have near colors (1 distance is between white and black) |
| [options.saturationImportance] | <code>String</code> | Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size) |
| [options.splitPower] | <code>String</code> | Approximation power in the first color splitting during process (from 2 to 16) |
| [options.colorValidator] | <code>String</code> | Callback with test to enable only some colors |
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc