Browse Source

Cleaned up README

pull/134/head
James Cryer 7 years ago committed by GitHub
parent
commit
84a338a49f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 121
      README.md

121
README.md

@ -120,60 +120,29 @@ The resemble.compare API provides a convenience function that is used as follows
const compare = require('resemblejs').compare; const compare = require('resemblejs').compare;
function getDiff(){ function getDiff(){
const options = {};
const options = { // The parameters can be Node Buffers
output: { // data is the same as usual with an additional getBuffer() function
errorColor: { compare(image1, image2, options, function (err, data) {
red: 255, if (err) {
green: 0, console.log('An error!')
blue: 255 } else {
}, console.log(data);
errorType: 'movement', /*
transparency: 0.3, {
largeImageThreshold: 1200, misMatchPercentage : 100, // %
useCrossOrigin: false, isSameDimensions: true, // or false
outputDiff: true dimensionDifference: { width: 0, height: -1 }, // defined if dimensions are not the same
}, getImageDataUrl: function(){}
scaleToSameSize: true, }
ignore: ['nothing', 'less', 'antialiasing', 'colors', 'alpha'], */
}; }
// The parameters can be Node Buffers });
// data is the same as usual with an additional getBuffer() function
compare(image1, image2, options, function (err, data) {
if (err) {
console.log('An error!')
} else {
console.log(data);
/*
{
misMatchPercentage : 100, // %
isSameDimensions: true, // or false
dimensionDifference: { width: 0, height: -1 }, // defined if dimensions are not the same
getImageDataUrl: function(){}
}
*/
}
});
} }
``` ```
### Node.js ### 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 #### Usage
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:
@ -183,37 +152,35 @@ 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: { 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 },
}, scaleToSameSize: true,
scaleToSameSize: true, ignore: ['nothing', 'less', 'antialiasing', 'colors', 'alpha'],
ignore: ['nothing', 'less', 'antialiasing', 'colors', 'alpha'], };
};
// 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();
``` ```
#### Tests #### Tests

Loading…
Cancel
Save