Browse Source

Update readme in response to #143

pull/146/head
james.cryer 6 years ago
parent
commit
f25ef01dd4
  1. 106
      README.md

106
README.md

@ -24,9 +24,9 @@
Retrieve basic analysis on an image: Retrieve basic analysis on an image:
```javascript ```javascript
var api = resemble(fileData).onComplete(function(data){ var api = resemble(fileData).onComplete(function(data) {
console.log(data); console.log(data);
/* /*
{ {
red: 255, red: 255,
green: 255, green: 255,
@ -40,9 +40,12 @@ var api = resemble(fileData).onComplete(function(data){
Use resemble to compare two images: Use resemble to compare two images:
```javascript ```javascript
var diff = resemble(file).compareTo(file2).ignoreColors().onComplete(function(data){ var diff = resemble(file)
console.log(data); .compareTo(file2)
/* .ignoreColors()
.onComplete(function(data) {
console.log(data);
/*
{ {
misMatchPercentage : 100, // % misMatchPercentage : 100, // %
isSameDimensions: true, // or false isSameDimensions: true, // or false
@ -50,10 +53,11 @@ var diff = resemble(file).compareTo(file2).ignoreColors().onComplete(function(da
getImageDataUrl: function(){} getImageDataUrl: function(){}
} }
*/ */
}); });
``` ```
Scale second image to dimensions of the first one: Scale second image to dimensions of the first one:
```javascript ```javascript
//diff.useOriginalSize(); //diff.useOriginalSize();
diff.scaleToSameSize(); diff.scaleToSameSize();
@ -68,22 +72,21 @@ You can also change the comparison method after the first analysis:
diff.ignoreAntialiasing(); diff.ignoreAntialiasing();
``` ```
And change the output display style: And change the output display style:
```javascript ```javascript
resemble.outputSettings({ resemble.outputSettings({
errorColor: { errorColor: {
red: 255, red: 255,
green: 0, green: 0,
blue: 255 blue: 255
}, },
errorType: 'movement', errorType: "movement",
transparency: 0.3, transparency: 0.3,
largeImageThreshold: 1200, largeImageThreshold: 1200,
useCrossOrigin: false, useCrossOrigin: false,
outputDiff: true outputDiff: true
}) });
// .repaint(); // .repaint();
``` ```
@ -91,13 +94,13 @@ It is possible to narrow down the area of comparison, by specifying a bounding b
```javascript ```javascript
resemble.outputSettings({ resemble.outputSettings({
boundingBox: { boundingBox: {
left: 100, left: 100,
top: 200, top: 200,
right: 200, right: 200,
bottom: 600 bottom: 600
} }
}) });
// .repaint(); // .repaint();
``` ```
@ -105,13 +108,13 @@ You can also exclude part of the image from comparison, by specifying the exclud
```javascript ```javascript
resemble.outputSettings({ resemble.outputSettings({
ignoredBox: { ignoredBox: {
left: 100, left: 100,
top: 200, top: 200,
right: 200, right: 200,
bottom: 600 bottom: 600
} }
}) });
// .repaint(); // .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: The resemble.compare API provides a convenience function that is used as follows:
``` js ```js
const compare = require('resemblejs').compare; const compare = require("resemblejs").compare;
function getDiff(){ function getDiff() {
const options = {}; const options = {};
// The parameters can be Node Buffers // The parameters can be Node Buffers
// data is the same as usual with an additional getBuffer() function // 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) { if (err) {
console.log('An error!') console.log("An error!");
} else { } else {
console.log(data); console.log(data);
/* /*
@ -156,11 +159,11 @@ function getDiff(){
The API under Node is the same as on the `resemble.compare` but promise based: The API under Node is the same as on the `resemble.compare` but promise based:
``` js ```js
const compareImages = require('resemblejs/compareImages'); const compareImages = require("resemblejs/compareImages");
const fs = require("mz/fs"); const fs = require("mz/fs");
async function getDiff(){ async function getDiff() {
const options = { const options = {
output: { output: {
errorColor: { errorColor: {
@ -168,25 +171,25 @@ async function getDiff(){
green: 0, green: 0,
blue: 255 blue: 255
}, },
errorType: 'movement', errorType: "movement",
transparency: 0.3, transparency: 0.3,
largeImageThreshold: 1200, largeImageThreshold: 1200,
useCrossOrigin: false, useCrossOrigin: false,
outputDiff: true outputDiff: true
}, },
scaleToSameSize: true, scaleToSameSize: true,
ignore: ['nothing', 'less', 'antialiasing', 'colors', 'alpha'], ignore: "antialiasing"
}; };
// The parameters can be Node Buffers // The parameters can be Node Buffers
// data is the same as usual with an additional getBuffer() function // data is the same as usual with an additional getBuffer() function
const data = await compareImages( const data = await compareImages(
await fs.readFile('./demoassets/People.jpg'), await fs.readFile("./demoassets/People.jpg"),
await fs.readFile('./demoassets/People2.jpg'), await fs.readFile("./demoassets/People2.jpg"),
options options
); );
await fs.writeFile('./output.png', data.getBuffer()); await fs.writeFile("./output.png", data.getBuffer());
} }
getDiff(); getDiff();
@ -196,24 +199,21 @@ getDiff();
To run the tests on Node (using Jest), type: To run the tests on Node (using Jest), type:
``` bash ```bash
npm run test 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. 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 #### Dockerfile
For convenience I've added a simple Dockerfile to run the NodeJS tests in an Ubuntu container 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 build -t huddle/resemble .
docker run huddle/resemble docker run huddle/resemble
``` ```
---
--------------------------------------
Created by [James Cryer](http://github.com/jamescryer) and the Huddle development team. Created by [James Cryer](http://github.com/jamescryer) and the Huddle development team.

Loading…
Cancel
Save