mirror of
https://github.com/ful1e5/apple_cursor.git
synced 2025-05-28 14:04:45 -04:00
🔣 Bitmaps matcher
This commit is contained in:
parent
7b7d5f7ae0
commit
9c22d7c5af
1 changed files with 12 additions and 4 deletions
|
@ -1,14 +1,22 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
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));
|
||||
export const matchImages = (img1Buff: Buffer, img2Buff: Buffer) => {
|
||||
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, {
|
||||
const out = pixelmatch(img1.data, img2.data, diff.data, width, height, {
|
||||
threshold: 0.3,
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
path.resolve(process.cwd(), "diff", `${out}.png`),
|
||||
diff.data
|
||||
);
|
||||
return out;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue