Created
February 9, 2024 12:41
-
-
Save sergot/b3b2b47118bd404ca76d044b7c71b211 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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