🖼 Frame Processing util

This commit is contained in:
ful1e5 2020-08-31 12:39:41 +05:30
parent 155dac47a8
commit af3440fa3a

View file

@ -0,0 +1,19 @@
import { PNG } from "pngjs";
import pixelmatch from "pixelmatch";
interface MatchImagesArgs {
img1Buff: Buffer;
img2Buff: Buffer;
}
export const matchImages = ({ img1Buff, img2Buff }: MatchImagesArgs) => {
const img1 = PNG.sync.read(img1Buff);
const img2 = PNG.sync.read(img2Buff);
const { width, height } = img1;
const diff = new PNG({ width, height });
return pixelmatch(img1.data, img2.data, diff.data, width, height, {
threshold: 0.25
});
};