Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dieterwalckiers/subimage-match
Lightweight library that finds matches of an image within another image
https://github.com/dieterwalckiers/subimage-match
Last synced: 15 days ago
JSON representation
Lightweight library that finds matches of an image within another image
- Host: GitHub
- URL: https://github.com/dieterwalckiers/subimage-match
- Owner: dieterwalckiers
- License: mit
- Created: 2019-08-07T12:38:33.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T11:36:01.000Z (over 1 year ago)
- Last Synced: 2024-08-10T02:49:11.141Z (3 months ago)
- Language: JavaScript
- Size: 292 KB
- Stars: 17
- Watchers: 2
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# matches-subimage
Lightweight library that finds matches of an image within another image, perfect for visual validation in testing scenarios.
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.Usage demo:
```js
const foundMatch = subImageMatch(img, subImg);
```## API
### subImageMatch(img, subImg[, options])
- `img1`, `img2` — Image data of the images to compare (`Buffer`, `Uint8Array` or `Uint8ClampedArray`).
- `options` is an object literal with only one property currently:
- `threshold` — Matching threshold, ranges from `0` to `1`. Smaller values make the comparison more sensitive. `0.1` by default.Returns a boolean indicating whether or not a match has been found
## Example usage
### Node.js
```js
const fs = require("fs");
const PNG = require("pngjs").PNG;
const subImageMatch = require("matches-subimage");const img = PNG.sync.read(fs.readFileSync("image.png"));
const subImg = PNG.sync.read(fs.readFileSync("sub_image.png"));
subImageMatch(img1, img2, {threshold: 0.1});
```## Install
Install with NPM:
```bash
npm install matches-subimage
```## [Changelog](https://github.com/dieterwalckiers/subimage-match/releases)