Huge News!Announcing our $40M Series B led by Abstract Ventures.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

Extract color palettes from images

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Extract Colors

Extract color palettes from images. Simple use, <4ko minified and no dependencies for browser.

Install

For browser

npm install 'extract-colors'

For node.js

Need to install dependency canvas

npm install 'extract-colors' 'canvas'

Usage

Browser

import extractColors from 'extract-colors'

const src = 'my-image.jpg'

extractColors(src)
  .then(console.log)
  .catch(console.error)

Node.js

const path = require('path')
const { extractColors } = require('extract-colors')

const src = './my-image.jpg'

extractColors(path.join(__dirname, src))
  .then(console.log)
  .catch(console.log)

Options

const src = 'my-image.jpg'

const options = {
  pixels: 10000,
  distance: 0.2,
  saturationImportance: 0.2,
  splitPower: 10,
  colorValidator: (red, green, blue, alpha = 255) => alpha > 250
}

extractColors(src, options).then(console.log)
FieldDefaultTypeDescription
pixels10000IntegerTotal pixel number of the resized picture for calculation
distance0.2NumberFrom 0 to 1 is the color distance to not have near colors (1 distance is between White and Black)
saturationImportance0.2NumberPower of the saturation weight during the process (0 is not used, 1 is equal to the area and more is more important for the saturation)
splitPower10IntegerApproximation power in the first color splitting during process (from 2 to 16)
colorValidator(red, green, blue, alpha = 255) => alpha > 250FunctionLamda function to disable some colors
crossOriginnullOnly for browser, can be 'Anonymous' to avoid CORS

Return of the promise

Array of colors with the followed properties:

[
  {
    hex: '#62342b',
    red: 98,
    green: 52,
    blue: 43,
    area: 0.5915,
    saturation: 0.2156862
  },
  ...
]
FieldExampleTypeDescription
hex#62342bStringcolor in hexadecimal string
red98Integerred canal from 0 to 255
green52Integergreen canal from 0 to 255
blue43Integerblue canal from 0 to 255
area0.5915Numberarea of the color and his neighbouring colors from 0 to 1
saturation0.2156862Numbercolor saturation from 0 to 1

Keywords

FAQs

Package last updated on 06 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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