Skip to content

Instantly share code, notes, and snippets.

@sergot
Created February 9, 2024 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergot/b3b2b47118bd404ca76d044b7c71b211 to your computer and use it in GitHub Desktop.
Save sergot/b3b2b47118bd404ca76d044b7c71b211 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
const PNG = require('pngjs').PNG;
const pixelmatch = require('pixelmatch');
const dir1 = 'dev4';
const dir2 = 'dev5';
fs.readdir(dir1, (err, files) => {
if (err) throw err;
files.forEach(file => {
if (path.extname(file) === '.png') {
const img1 = PNG.sync.read(fs.readFileSync(path.join(dir1, file)));
const img2 = PNG.sync.read(fs.readFileSync(path.join(dir2, file)));
const {width, height} = img1;
const diff = new PNG({width, height});
pixelmatch(img1.data, img2.data, diff.data, width, height, {threshold: 0.1});
diff.pack().pipe(fs.createWriteStream(`diff_${file}`));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment