mirror of
https://github.com/ful1e5/apple_cursor.git
synced 2025-06-06 01:31:15 -04:00
🧹 Diff files cleanup
This commit is contained in:
parent
b4a678497c
commit
f0ca4c5689
1 changed files with 8 additions and 16 deletions
|
@ -1,27 +1,19 @@
|
||||||
import fs from "fs";
|
|
||||||
import path from "path";
|
|
||||||
import { PNG } from "pngjs";
|
import { PNG } from "pngjs";
|
||||||
import pixelmatch from "pixelmatch";
|
import pixelmatch from "pixelmatch";
|
||||||
|
|
||||||
export const matchImages = (img1Buff: Buffer, img2Buff: Buffer) => {
|
interface MatchImagesArgs {
|
||||||
|
img1Buff: Buffer;
|
||||||
|
img2Buff: Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const matchImages = ({ img1Buff, img2Buff }: MatchImagesArgs) => {
|
||||||
const img1 = PNG.sync.read(img1Buff);
|
const img1 = PNG.sync.read(img1Buff);
|
||||||
const img2 = PNG.sync.read(img2Buff);
|
const img2 = PNG.sync.read(img2Buff);
|
||||||
const { width, height } = img1;
|
const { width, height } = img1;
|
||||||
|
|
||||||
const diff = new PNG({ width, height });
|
const diff = new PNG({ width, height });
|
||||||
|
|
||||||
const out = pixelmatch(img1.data, img2.data, diff.data, width, height, {
|
return pixelmatch(img1.data, img2.data, diff.data, width, height, {
|
||||||
threshold: 0.3,
|
threshold: 0.25,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.env.NODE_ENV === "development") {
|
|
||||||
const diffFilesPath = path.resolve(process.cwd(), "diff");
|
|
||||||
if (!fs.existsSync(diffFilesPath)) fs.mkdirSync(diffFilesPath);
|
|
||||||
fs.writeFileSync(
|
|
||||||
path.resolve(diffFilesPath, `${out}.png`),
|
|
||||||
PNG.sync.write(diff)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue