mirror of
https://github.com/ful1e5/apple_cursor.git
synced 2025-05-29 22:45:14 -04:00
🔳 Pixel Matching utils
This commit is contained in:
parent
2a0be3706d
commit
687a5f97e2
1 changed files with 14 additions and 0 deletions
14
src/utils/matchImages.ts
Normal file
14
src/utils/matchImages.ts
Normal 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,
|
||||||
|
});
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue