@ -24,7 +24,7 @@
Retrieve basic analysis on an image:
```javascript
var api = resemble(fileData).onComplete(function(data){
var api = resemble(fileData).onComplete(function(data) {
console.log(data);
/*
{
@ -40,7 +40,10 @@ var api = resemble(fileData).onComplete(function(data){
Use resemble to compare two images:
```javascript
var diff = resemble(file).compareTo(file2).ignoreColors().onComplete(function(data){
var diff = resemble(file)
.compareTo(file2)
.ignoreColors()
.onComplete(function(data) {
console.log(data);
/*
{
@ -50,10 +53,11 @@ var diff = resemble(file).compareTo(file2).ignoreColors().onComplete(function(da
getImageDataUrl: function(){}
}
*/
});
});
```
Scale second image to dimensions of the first one:
```javascript
//diff.useOriginalSize();
diff.scaleToSameSize();
@ -68,7 +72,6 @@ You can also change the comparison method after the first analysis:
diff.ignoreAntialiasing();
```
And change the output display style:
```javascript
@ -78,12 +81,12 @@ resemble.outputSettings({
green: 0,
blue: 255
},
errorType: 'movement' ,
errorType: "movement" ,
transparency: 0.3,
largeImageThreshold: 1200,
useCrossOrigin: false,
outputDiff: true
})
});
// .repaint();
```
@ -97,7 +100,7 @@ resemble.outputSettings({
right: 200,
bottom: 600
}
})
});
// .repaint();
```
@ -111,7 +114,7 @@ resemble.outputSettings({
right: 200,
bottom: 600
}
})
});
// .repaint();
```
@ -125,16 +128,16 @@ You can modify this behaviour by setting the `largeImageThreshold` option to a d
The resemble.compare API provides a convenience function that is used as follows:
``` js
const compare = require('resemblejs' ).compare;
```js
const compare = require("resemblejs" ).compare;
function getDiff(){
function getDiff() {
const options = {};
// The parameters can be Node Buffers
// data is the same as usual with an additional getBuffer() function
compare(image1, image2, options, function (err, data) {
compare(image1, image2, options, function(err, data) {
if (err) {
console.log('An error!')
console.log("An error!");
} else {
console.log(data);
/*
@ -156,11 +159,11 @@ function getDiff(){
The API under Node is the same as on the `resemble.compare` but promise based:
``` js
const compareImages = require('resemblejs/compareImages' );
```js
const compareImages = require("resemblejs/compareImages" );
const fs = require("mz/fs");
async function getDiff(){
async function getDiff() {
const options = {
output: {
errorColor: {
@ -168,25 +171,25 @@ async function getDiff(){
green: 0,
blue: 255
},
errorType: 'movement' ,
errorType: "movement" ,
transparency: 0.3,
largeImageThreshold: 1200,
useCrossOrigin: false,
outputDiff: true
},
scaleToSameSize: true,
ignore: ['nothing', 'less', 'antialiasing', 'colors', 'alpha'],
ignore: "antialiasing"
};
// The parameters can be Node Buffers
// data is the same as usual with an additional getBuffer() function
const data = await compareImages(
await fs.readFile('./demoassets/People.jpg' ),
await fs.readFile('./demoassets/People2.jpg' ),
await fs.readFile("./demoassets/People.jpg" ),
await fs.readFile("./demoassets/People2.jpg" ),
options
);
await fs.writeFile('./output.png' , data.getBuffer());
await fs.writeFile("./output.png" , data.getBuffer());
}
getDiff();
@ -196,24 +199,21 @@ getDiff();
To run the tests on Node (using Jest), type:
``` bash
```bash
npm run test
```
There are also some in-browser tests. To run these install and run a http-server such as [http-server ](https://github.com/indexzero/http-server ) from the root of the project. Then in the browser, navigate to `localhost:8080/chai-tests/test.html` , open up the developer console to see the results.
#### Dockerfile
For convenience I've added a simple Dockerfile to run the NodeJS tests in an Ubuntu container
``` bash
```bash
docker build -t huddle/resemble .
docker run huddle/resemble
```
--------------------------------------
---
Created by [James Cryer ](http://github.com/jamescryer ) and the Huddle development team.