https://github.com/transitive-bullshit/phash-im
Perceptual image hashing provided by imagemagick.
https://github.com/transitive-bullshit/phash-im
hash imagemagick perceptual-hashing phash
Last synced: about 1 year ago
JSON representation
Perceptual image hashing provided by imagemagick.
- Host: GitHub
- URL: https://github.com/transitive-bullshit/phash-im
- Owner: transitive-bullshit
- Created: 2018-04-04T09:55:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-11T23:11:27.000Z (almost 6 years ago)
- Last Synced: 2025-04-17T03:53:23.616Z (about 1 year ago)
- Topics: hash, imagemagick, perceptual-hashing, phash
- Language: JavaScript
- Size: 3.59 MB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# phash-im
> Perceptual image hashing via [imagemagick](http://www.fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/index.html).
[](https://www.npmjs.com/package/phash-im) [](https://travis-ci.com/transitive-bullshit/phash-im) [](https://standardjs.com)
There are many ways to compute [perceptual image hashes](https://www.wikiwand.com/en/Perceptual_hashing), with the open source [pHash](http://www.phash.org/) library being one of the most popular. After researching a few dozen different approaches, we've settled on imagemagick's implementation, for the following reasons:
- **modern** - based on an [approach](http://www.naturalspublishing.com/files/published/54515x71g3omq1.pdf) from 2011
- **robust** against a variety of [attacks](http://www.fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/index.html)
- thoroughly **[tested](https://github.com/transitive-bullshit/phash-im/tree/master/index.test.js)**
- **easy to install** - [imagemagick](http://imagemagick.org) has great cross-platform support
## Install
- Install a recent version of [imagemagick](http://imagemagick.org) >= `v7` (`brew install imagemagick` on Mac OS).
```bash
npm install --save phash-im
# or
yarn add phash-im
```
## Usage
```js
const phash = require('phash-im')
const hash1 = await phash.compute('./media/lena.png')
const hash2 = await phash.compute('./media/barbara.png')
const diff = await phash.compare(hash1, hash2)
```
## API
### phash.compute(input)
Returns: `Promise>`
Computes the perceptual hash of the given image. Note that the result will be an array of 42 floating point values, corresponding to the 7 image moments comprised of 2 points each across 3 color channels RGB (`7 * 2 * 3 = 42`).
#### input
Type: `String`
**Required**
Path to an image file.
### phash.compare(hash1, hash2)
Returns: `Promise`
Computes the L2 norm of the two hashes returnd by `phash.compute` (sum of squared differences).
#### hash1
Type: `Array`
**Required**
Perceptual hash of first image.
#### hash2
Type: `Array`
**Required**
Perceptual hash of second image.
## Related
- [phash-imagemagick](https://github.com/scienceai/phash-imagemagick) - Alternate version of this module which parses imagemagick output instead of using json.
- [pHash](http://www.phash.org/) - A popular open source perceptual hash library.
## License
MIT © [Travis Fischer](https://github.com/transitive-bullshit)
Support my OSS work by following me on twitter