https://github.com/ytetsuro/image-hash
Image to dhash for Browser
https://github.com/ytetsuro/image-hash
dhash hacktoberfest imagediff typescript
Last synced: about 1 year ago
JSON representation
Image to dhash for Browser
- Host: GitHub
- URL: https://github.com/ytetsuro/image-hash
- Owner: ytetsuro
- License: mit
- Created: 2019-08-25T12:42:57.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:06:20.000Z (over 3 years ago)
- Last Synced: 2025-04-21T15:12:32.335Z (about 1 year ago)
- Topics: dhash, hacktoberfest, imagediff, typescript
- Language: TypeScript
- Homepage:
- Size: 1.37 MB
- Stars: 3
- Watchers: 2
- Forks: 6
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/ytetsuro/image-hash)
[](https://codecov.io/gh/ytetsuro/image-hash)
# Browser image hash
This is browser image hash generator.
This library is made to generate the same hash as [image-hash](https://github.com/JohannesBuchner/imagehash) as much as possible.
## Supported.
* difference hashing ([dHash](http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html))
## Feature Suuport.
* average hashing ([aHash](http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html))
* perception hashing ([pHash](http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html))
* wavelet hashing ([wHash](https://fullstackml.com/2016/07/02/wavelet-image-hash-in-python/))
## Installation
```bash
$ npm install browser-image-hash
```
## Basic Using
```typescript
import {DifferenceHashBuilder, Hash} from 'browser-image-hash';
document.addEventListener('DOMContentLoaded', async () => {
const builder = new DifferenceHashBuilder();
const targetURL = new URL('./example.jpg', window.location.href);
const destHash = await builder.build(targetURL);
const srcHash = new Hash('0111011001110000011110010101101100110011000100110101101000111000');
if (srcHash.getHammingDistance(destHash) <= 10) {
console.log('Resembles');
return;
}
console.log('Different');
});
```
⚠️ Since this library uses canvas, please be careful of the same origin policy.
[Allowing cross-origin use of images and canvas](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image)