resemblejs
Advanced tools
Comparing version 2.2.4 to 2.2.5
{ | ||
"name": "resemblejs", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "Image analysis and comparison with HTML5", | ||
@@ -23,3 +23,18 @@ "main": "resemble.js", | ||
}, | ||
"homepage": "https://github.com/Huddle/Resemble.js" | ||
"homepage": "https://github.com/Huddle/Resemble.js", | ||
"scripts": { | ||
"test": "jest ./nodejs-tests", | ||
"test-watch": "jest --watch ./nodejs-tests" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"jest": "^20.0.4", | ||
"jest-cli": "^20.0.4" | ||
}, | ||
"peerDependencies": { | ||
"canvas": "^1.6.5" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
Resemble.js | ||
========== | ||
Analyse and compare images with Javascript and HTML5. [More info & Resemble.js Demo](http://huddle.github.com/Resemble.js/). If you need NodeJS support, take a look at [node-resemble](https://github.com/ddo/node-resemble) or [node-resemble-v2](https://github.com/peter-mouland/node-resemble-v2). | ||
Analyse and compare images with Javascript and HTML5. [More info & Resemble.js Demo](http://huddle.github.com/Resemble.js/). Compatible with Node.js. | ||
@@ -86,5 +86,56 @@ ![Two image diff examples side-by-side, one pink, one yellow.](https://raw.github.com/Huddle/Resemble.js/master/demoassets/readmeimage.jpg "Visual image comparison") | ||
### Node.js | ||
#### Installation | ||
On Node, Resemble uses the `canvas` package instead of the native canvas support in the browser. To prevent browser users from being forced into installing Canvas, it's included as a peer dependency which means you have to install it alongside Resemble. | ||
Canvas relies on some native image manipulation libraries to be install on the system. Please read the [Canvas installation instructions](https://www.npmjs.com/package/canvas) for OSX/Windows/Linux. | ||
*Example commands for installation on OSX* | ||
``` bash | ||
npm install resemblejs | ||
brew install pkg-config cairo libpng jpeg giflib | ||
npm install canvas | ||
``` | ||
#### Usage | ||
The API under Node is the same as on the browser with one addition, a promise based `compareImage` convenience function that is used as follows: | ||
``` js | ||
const compareImage = require('resemblejs/compareImages'); | ||
// The parameters can be Node Buffers | ||
// data is the same as usual with an additional getBuffer() function | ||
const data = await compareImages( | ||
fs.readFileSync('./demoassets/People.jpg'), | ||
fs.readFileSync('./demoassets/People2.jpg') | ||
); | ||
fs.writeFileSync('./output.png', data.getBuffer()); | ||
``` | ||
#### Tests | ||
To run the tests on Node (using Jest), type: | ||
``` bash | ||
npm run test | ||
``` | ||
#### Dockerfile | ||
For convenience I've added a simple Dockerfile to run the NodeJS tests in an Ubuntu container | ||
``` bash | ||
docker build -t huddle/resemble . | ||
docker run huddle/resemble | ||
``` | ||
-------------------------------------- | ||
Created by [James Cryer](http://github.com/jamescryer) and the Huddle development team. |
@@ -64,3 +64,9 @@ /* | ||
var useCrossOrigin = true; | ||
var document = typeof window != "undefined" ? window.document : {}; | ||
var document = typeof window != "undefined" ? window.document : { | ||
createElement: function() { | ||
// This will work as long as only createElement is used on window.document | ||
var Canvas = require('canvas'); | ||
return new Canvas(); | ||
} | ||
}; | ||
@@ -155,4 +161,12 @@ var resemble = function( fileData ){ | ||
var fileReader; | ||
var hiddenImage = new Image(); | ||
var hiddenImage; | ||
if (typeof Image !== 'undefined') { | ||
hiddenImage = new Image(); | ||
} else { | ||
var CanvasImage = require('canvas').Image; | ||
hiddenImage = new CanvasImage(); | ||
hiddenImage.setAttribute = function setAttribute() { }; | ||
} | ||
if(useCrossOrigin) { | ||
@@ -162,6 +176,6 @@ hiddenImage.setAttribute('crossorigin', 'anonymous'); | ||
hiddenImage.onerror = function () { | ||
hiddenImage.onerror = function () { | ||
hiddenImage.onerror = null; //fixes pollution between calls | ||
images.push({ error : "Image load error."}); | ||
callback(); | ||
callback(); | ||
}; | ||
@@ -207,3 +221,5 @@ | ||
callback(fileData, fileData.width, fileData.height); | ||
} else if (typeof Buffer !== 'undefined' && fileData instanceof Buffer){ | ||
// If we have Buffer, assume we're on Node+Canvas and its supported | ||
hiddenImage.src = fileData; | ||
} else { | ||
@@ -489,2 +505,9 @@ fileReader = new FileReader(); | ||
}; | ||
if (hiddenCanvas.toBuffer) { | ||
data.getBuffer = function() { | ||
context.putImageData(imgd, 0, 0); | ||
return hiddenCanvas.toBuffer(); | ||
} | ||
} | ||
} | ||
@@ -491,0 +514,0 @@ |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
241094
21
1074
141
1
3
2