Skip to content

Commit d77cb78

Browse files
author
dyte
committed
Standard operation of subImageMatch + extended tests
1 parent c3fff5e commit d77cb78

File tree

13 files changed

+141
-1268
lines changed

13 files changed

+141
-1268
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
11
# matches-subimage
2-
Lightweight library that finds matches of an image within another image
2+
3+
Lightweight library that finds matches of an image within another image, perfect for visual validation in testing scenarios.
4+
Heavily inspired by (read: blatantly copied some subroutines from) [pixelmatch](https://github.com/mapbox/pixelmatch), and just like [pixelmatch](https://github.com/mapbox/pixelmatch), its advantages are that it's fast and lightweight, with zero dependencies.
5+
6+
Usage demo:
7+
```js
8+
const foundMatch = subImageMatch(img, subImg);
9+
```
10+
11+
## API
12+
13+
### pixelmatch(img, subImg[, options])
14+
15+
- `img1`, `img2` — Image data of the images to compare (`Buffer`, `Uint8Array` or `Uint8ClampedArray`).
16+
- `options` is an object literal with only one property currently:
17+
- `threshold` — Matching threshold, ranges from `0` to `1`. Smaller values make the comparison more sensitive. `0.1` by default.
18+
19+
Returns a boolean indicating whether or not a match has been found
20+
21+
## Example usage
22+
23+
### Node.js
24+
25+
```js
26+
const fs = require("fs");
27+
const PNG = require("pngjs").PNG;
28+
const subImageMatch = require("subimage-match");
29+
30+
const img = PNG.sync.read(fs.readFileSync("image.png"));
31+
const subImg = PNG.sync.read(fs.readFileSync("sub_image.png"));
32+
subImageMatch(img1.data, img2.data, {threshold: 0.1});
33+
```
34+
35+
## Install
36+
37+
Install with NPM:
38+
39+
```bash
40+
npm install pixelmatch
41+
```
42+
43+
## [Changelog](https://github.com/dieterwalckiers/subimage-match/releases)

0 commit comments

Comments
 (0)