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. 59
      README.md

59
README.md

@ -120,26 +120,10 @@ 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,
green: 0,
blue: 255
},
errorType: 'movement',
transparency: 0.3,
largeImageThreshold: 1200,
useCrossOrigin: false,
outputDiff: true
},
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) { if (err) {
console.log('An error!') console.log('An error!')
} else { } else {
@ -152,28 +136,13 @@ compare(image1, image2, options, function (err, data) {
getImageDataUrl: function(){} 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,8 +152,7 @@ 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,
@ -199,21 +167,20 @@ const options = {
}, },
scaleToSameSize: true, scaleToSameSize: true,
ignore: ['nothing', 'less', 'antialiasing', 'colors', 'alpha'], ignore: ['nothing', 'less', 'antialiasing', 'colors', 'alpha'],
}; };
// The parameters can be Node Buffers
// data is the same as usual with an additional getBuffer() function // The parameters can be Node Buffers
const data = await compareImages( // 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/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