Node

Source:

Node exported functions.

Examples

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)
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)

Methods

(inner) extractColors(picture, optionsopt) → {Array.<Object>}

Source:

Extract colors from a picture.

Parameters:
Name Type Attributes Description
picture String | Image | ImageData

Src, Image or ImageData

options Object <optional>

Optional data

Properties
Name Type Attributes Description
pixels String <optional>

Total pixel number of the resized picture for calculation

distance String <optional>

From 0 to 1 is the color distance to not have near colors (1 distance is between white and black)

saturationImportance String <optional>

Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size)

splitPower String <optional>

Approximation power in the first color splitting during process (from 2 to 16)

colorValidator String <optional>

Callback with test to enable only some colors

Returns:
Type
Array.<Object>

(inner) extractColorsFromImageData(imageData, optionsopt) → {Array.<Object>}

Source:

Extract colors from an ImageData object.

Parameters:
Name Type Attributes Description
imageData ImageData
options Object <optional>

Optional data

Properties
Name Type Attributes Description
pixels String <optional>

Total pixel number of the resized picture for calculation

distance String <optional>

From 0 to 1 is the color distance to not have near colors (1 distance is between white and black)

saturationImportance String <optional>

Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size)

splitPower String <optional>

Approximation power in the first color splitting during process (from 2 to 16)

colorValidator String <optional>

Callback with test to enable only some colors

Returns:
Type
Array.<Object>

(inner) extractColorsFromSrc(src, optionsopt) → {Array.<Object>}

Source:

Extract colors from a path. The image will be downloaded.

Parameters:
Name Type Attributes Description
src String
options Object <optional>

Optional data

Properties
Name Type Attributes Description
pixels String <optional>

Total pixel number of the resized picture for calculation

distance String <optional>

From 0 to 1 is the color distance to not have near colors (1 distance is between white and black)

saturationImportance String <optional>

Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size)

splitPower String <optional>

Approximation power in the first color splitting during process (from 2 to 16)

colorValidator String <optional>

Callback with test to enable only some colors

Returns:
Type
Array.<Object>

(inner) getImageData(image, pixels) → {ImageData}

Source:

Extract ImageData from image. Reduce image to a pixel count.

Parameters:
Name Type Description
image Image

Source image

pixels Number

Maximum number of pixels for process

Returns:
Type
ImageData