Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sensu/color-extractor

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sensu/color-extractor

Extract color palettes from images

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

color-extractor build status

An updated fork of node-colour-extractor with proper error handling and tests

Extract color palettes from photos using Node.js.

Installation

Is as simple as with any other Node.js module:

$ npm install color-extractor

NOTE: color-extractor depends on gm module, which in turn depends on GraphicsMagick.

Sample

sample

Usage

color-extractor exports two functions:

ce = require('color-extractor')
ce.topColors('Photos/Cats/01.jpg', function (error, colors) {
  console.log(colors);
});

topColors function takes two arguments:

  • path to your photo,
  • a callback function.

Callback function will be passed an Array with RGB triplet of each color and its frequency:

[
  [1,   [46, 70, 118]],
  [0.3, [0,   0,   2]],
  [0.2, [12,  44,  11]]
]

The second function, colorKey, returns an array with nine colors, where each one can be mapped to a 3x3 box, ie. super-pixelised representation of the photo.

ce.colorKey('Photos/Cats/999999.jpg', function (error, colors) {
  database.store('color-keys', photoId, colors);
  res.send(colors);
  // render colors to user while they wait for the photo to load.
  // (or something equally brilliant)
});

Utilities

color-extractor exports two more utility functions:

> ce.rgb2hex(100, 10, 12);
'#640a0c'
> ce.rgb2hex([44, 44, 44]);
'#2c2c2c'
> ce.hex2rgb('#ffffff');
[255, 255, 255]
> ce.hex2rgb('45c092')
[69, 192, 146]

License

color-extractor is published under MIT license, please see the LICENSE file for full details.

Photos used in the sample can be downloaded from Flickr:

FAQs

Package last updated on 01 Jun 2018

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