| var main = require(__dirname+'/../main.js'), | ||
| assert = require('assert'); | ||
| var extract = main.extract; | ||
| extract.imageMagick(__dirname+'/nodelogo.png',function(err,data){ | ||
| if(err){ | ||
| console.log('IMAGE MAGICK ERROR ',err); | ||
| process.exit(1); | ||
| } | ||
| console.log('data: ',data); | ||
| assert.ok(data.length == 16); | ||
| assert.ok(data[0].percent); | ||
| assert.ok(data[0].rgb); | ||
| }); | ||
| var main = require(__dirname+'/../main.js'),assert = require('assert'); | ||
| var range = main.rgbRange(10,200,50); | ||
| console.log('range format'); | ||
| console.log("\t",range); | ||
| assert.ok(range.g1); | ||
| assert.ok(range.r2); | ||
| assert.ok(range.b1 < range.b2); | ||
+4
-3
@@ -1,5 +0,3 @@ | ||
| var spawn = require('childprocess').spawn; | ||
| var match = new ColorMatch(); | ||
@@ -15,2 +13,4 @@ // | ||
| exports.quickMatch = function(rgb1,rgb2){ | ||
| var match = new ColorMatch(); | ||
| return match.quickMatch(rgb1,rgb2); | ||
@@ -24,2 +24,3 @@ } | ||
| exports.rgbRange = function(r,g,b){ | ||
| var match = new ColorMatch(); | ||
| return match.rgbRange(r,g,b); | ||
@@ -76,5 +77,5 @@ } | ||
| return $res; | ||
| return res; | ||
| } | ||
| }; | ||
+0
-1
@@ -42,3 +42,2 @@ var spawn = require('child_process').spawn; | ||
| parts = str.trim().replace(/([(]) |(,) |:( )/g,'$1$2$3').split(' '); | ||
| console.log(parts); | ||
| if(parts.length >= 2) { | ||
@@ -45,0 +44,0 @@ var count = parts[0]; |
+34
-2
@@ -1,2 +0,34 @@ | ||
| var extract = require(__dirname+'/exract.js'), | ||
| match = require(__dirname+'/match.js'); | ||
| var extract = require(__dirname+'/extract.js'), | ||
| match = require(__dirname+'/colormatch.js'); | ||
| module.exports = { | ||
| // | ||
| // extract libraries | ||
| // .imageMagick(path to image,cb); | ||
| // | ||
| extract:extract, | ||
| // | ||
| // color match constructor. if you need tailored tollerances make a new one of these. | ||
| // new ColorMatch(options) | ||
| // valid options are | ||
| // tollerance: default 15 | ||
| // this is the window around a colors data points that will allways match. adds fuzzyness to matcher. | ||
| ColorMatch:match.ColorMatch, | ||
| // | ||
| // is a color a close visual match of the other color? | ||
| // | ||
| // rgb as an array with at least 3 values | ||
| // [r,g,b] | ||
| // this matching algo becomes fuzzier as it approches grey. which is logical because greys are more visually simmilar. | ||
| // | ||
| quickMatch:function(rgb1,rgb2){ | ||
| return match.quickMatch(rgb1,rgb2); | ||
| }, | ||
| // | ||
| // rgbRange | ||
| // | ||
| rgbRange:function(r,g,b){ | ||
| return match.rgbRange(r,g,b) ; | ||
| } | ||
| }; |
+4
-1
| { | ||
| "name": "colormatch" | ||
| , "description": "A module for extracting colors from images and for generating lookup ranges that accept rgb and outputs ranges of rgb values for db lookups. Right now it uses ImageMagik in a child process to reduce the colorspace and return the top colors of an image. Alterntives with node-canvas or an all js jpeg decoder could be used. The latterwith the same js color quantization algorthims that would be needed to reduce the colorspace of the former." | ||
| , "version": "0.0.0" | ||
| , "version": "0.0.1" | ||
| , "author": "Ryan Day <soldair@gmail.com>" | ||
@@ -13,3 +13,6 @@ , "keywords": ["image", "indexing", "color", "search"] | ||
| } | ||
| ,"scripts":{ | ||
| "test":"node ./test/extract.js & node ./test/match.js" | ||
| } | ||
| ,"engines":{"node":">=0.6.0"} | ||
| } |
+53
-8
| no time to write a good readme yet sorry. | ||
| exports | ||
| ## ColorMatch | ||
| match | ||
| quickMatch | ||
| rgbRange | ||
| colorMatch | ||
| Ever want to compare colors? ever want to extract colors from images? | ||
| You can extract the dominant colors in an image with my extract.imageMagick function. (more libs comming soon) | ||
| You can use a matching algo that uses simple range math. Simple is nice! | ||
| extract | ||
| imageMagick < extract image data via image magick | ||
| If you index those colors in a system that has efficient range queries the output of the rgbRange function will be distinct r,g,b ranges that match visually | ||
| ### API | ||
| ####matching api | ||
| - quickMatch(rgb1,rgb2) | ||
| do these colors match? this shows the logic required to use the provided rgb ranges and is useful for quick matching colors. | ||
| rgb1 and rgb2 should be arrays with at least 3 int values in the format of [red,green,blue] | ||
| - rgbRange(r,g,b) | ||
| this takes 3 arguments reg,green, and blue. it expects them to be ints. | ||
| it returns an object. this object has keys r1,g1,b1 and r2,b2,g2 defined | ||
| {r1:0,r2:0,g1:0,g2:0,b1:0,b2:0} | ||
| to use this data all values in r between r1 and r2 are valid matches | ||
| the same follows for g and b | ||
| - ColorMatch(options) | ||
| this is the core object for color match right now. | ||
| The only reason you would want to make a new colormatch instance is to adjust the fuzzy tollerance applied to colors. | ||
| It is set to 15 points in the rgb space by default | ||
| ####extracting api | ||
| all values are nested under the main export .extract | ||
| the behavior of color extraction is to: | ||
| 1. reduce the colorspace in an image down to 16 colors | ||
| 2. output how much of the image is that color. | ||
| 3. output the data in a consistent format | ||
| example output: | ||
| [{ percent: 9.996918248611745e-37, rgb: [ '70', '72', '62' ] }] | ||
| supported extractors | ||
| - imageMagick(path,callback) | ||
| this shells out to convert (a part of the imageMagick suite) | ||
| if you dont have it installed it wont work. | ||
| ####desired extractors | ||
| node-canvas | ||
| js only png | ||
| js only jpeg | ||
| var extract = require(__dirname+'/../extract.js'); | ||
| console.log(extract); | ||
| extract.imageMagick(__dirname+'/nodelogo.png',function(err,data){ | ||
| console.log('error: ',err); | ||
| console.log('data: ',data); | ||
| }); | ||
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
9445
46.48%9
12.5%156
38.05%61
281.25%4
33.33%