mapbox / pixelmatch

The smallest, simplest and fastest JavaScript pixel-level image comparison library
ISC License
6.17k stars 307 forks source link

Any JPG demo code available? #45

Closed rcfrias closed 5 years ago

mourner commented 5 years ago

No, but it doesn't matter for the algorithm.

ko4ergins commented 5 years ago

Hi Vladimir! I tried to comparison two .jpg images but I have the error. Could you, please, provide a small example?

./node_modules/pixelmatch/bin/pixelmatch 1.jpg 2.jpg output.png 0.1

ko4ergins commented 5 years ago

Hi @rcfrias! I wrote some ex.

const fs = require('fs');
const pixelmatch = require('pixelmatch');
const PNG = require('pngjs').PNG;

const JPEG = require('jpeg-js');

const jpegData1 = fs.readFileSync('img1.jpg');
const img1 = JPEG.decode(jpegData1);

const jpegData2 = fs.readFileSync('img2.jpg');
const img2 = JPEG.decode(jpegData2);

const diff = new PNG({ width: img1.width, height: img1.height });

pixelmatch(img1.data, img2.data, diff.data, img1.width, img1.height, { threshold: 0.1 });

diff.pack().pipe(fs.createWriteStream('diff.png'));