mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2025-05-23 19:46:57 -04:00
🖼 Frame Processing util
This commit is contained in:
parent
155dac47a8
commit
af3440fa3a
1 changed files with 19 additions and 0 deletions
19
packages/common/src/utils/matchImages.ts
Normal file
19
packages/common/src/utils/matchImages.ts
Normal 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
|
||||||
|
});
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue