apple_cursor/src/utils/matchImages.ts
2020-11-01 10:38:13 +05:30

19 lines
470 B
TypeScript

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.1,
});
};