🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

color-graph

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-graph

Get color graph of canvas

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

#Color Graph

Color Graph is a node module that takes an HTML canvas and performs various collection/statistical tasks on it. This can be used to create color palates, or to help create generative artworks from image data.

I will include a browser version soon.

#Example

var fs = require('fs')
  , ColorGraph = require('./index.js')
  , Canvas = require('canvas')
  , Image = Canvas.Image;

var imgRaw = fs.readFileSync('./lisa.jpg'),
  img = new Image;
  img.src = imgRaw;

var canvas = new Canvas(img.width, img.height),
  ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);

var d = ColorGraph({trim: 0});

//Get all colors in a canvas - one color for each pixel
var points = d.getPoints(canvas);
console.log(points);

//Get a list of all colors in a canvas along with their occurrence count
d.getGraph(canvas, function(colorGraph){
  console.log(colorGraph);
});

//Get a list of 5 of the main colors in an image. Uses clustering to work out general color groups then averages them.
d.getDominantColors(canvas, function(results){
  console.log('RGB:');
  console.log(results);
});

If you have any issues or requests please make an issue and I'll do my best to include it.

Keywords

color

FAQs

Package last updated on 12 Feb 2014

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