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.1.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
increased by20.4%
Maintainers
1
Weekly downloads
 
Created
Source

Extract Colors

package version npm bundle size Dependencies CI code coverage GNU GPL software License

Extract color palettes from images.
Simple use, < 5ko minified, fast process and no dependencies for browser.
Dependency to canvas for node.js

3 examples of colors extraction

Requirements

Browsers

  • Firefox: 29+
  • Chrome: 33+
  • Edge: 12+
  • Opera: 19+
  • Safari: 8+
  • Webview Android: 4.4.3+
  • Samsung Internet: 2.0+
  • Internet Explorer

Node

  • Node.js: 0.12+

Install

For browser

npm install --save extract-colors

For node.js

Need to install dependency canvas

npm install --save extract-colors canvas

Usage

Browser example

import extractColors from 'extract-colors'

const src = 'my-image.jpg'

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

You can use different types for src param (String for a path of image, Image or ImageData).
If you use ImageData type, be carrefull because the extractor will not optimize the process (it will not reduce the count of pixels).

Node.js example

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)

You can use different types for src param (String for a path of image or ImageData).
If you use ImageData type, be carrefull because the extractor will not optimize the process (it will not reduce the count of pixels).

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)
  .catch(console.error)

pixels
Total pixel number of the resized picture for calculation
Type: Integer
Default: 10000

distance
From 0 to 1 is the color distance to not have near colors (1 distance is between white and black)
Type: Number
Default: 0.2

saturationImportance
Power of the saturation weight during the process (0 is not used, 1 is only saturation and not area size)
Type: Number
Default: 0.2

splitPower
Approximation power in the first color splitting during process (from 2 to 16)
Type: Integer
Default: 10

colorValidator
Test function to enable only some colors
Type: Function
Default: (red, green, blue, alpha = 255) => alpha > 250

crossOrigin
Only for browser, can be 'Anonymous' to avoid CORS
Type: String
Default: null

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

API doc

Read the API doc here

License

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.

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.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Keywords

FAQs

Package last updated on 14 Nov 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