🔳 Pixel Matching utils

This commit is contained in:
ful1e5 2020-08-28 20:37:59 +05:30
parent 2a0be3706d
commit 687a5f97e2

14
src/utils/matchImages.ts Normal file
View file

@ -0,0 +1,14 @@
import fs from "fs";
import { PNG } from "pngjs";
import pixelmatch from "pixelmatch";
export const matchImages = (img1Path: string, img2Path: string) => {
const img1 = PNG.sync.read(fs.readFileSync(img1Path));
const img2 = PNG.sync.read(fs.readFileSync(img2Path));
const { width, height } = img1;
const diff = new PNG({ width, height });
return pixelmatch(img1.data, img2.data, diff.data, width, height, {
threshold: 0.3,
});
};