# phash-im

> Perceptual image hashing provided by imagemagick.

Latest version **1.0.1** (published 2018-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install phash-im
pnpm add phash-im
yarn add phash-im
bun add phash-im
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-05-10 |
| First published | 2018-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Travis Fischer |
| Maintainers | fisch0920 |
| Keywords | phash, image, perceptual, hash, imagemagick |

## Links

- npm: https://www.npmjs.com/package/phash-im
- Repository: https://github.com/transitive-bullshit/phash-im
- npm.io page: https://npm.io/package/phash-im

## Dependencies (1)

- [execa](https://npm.io/package/execa.md) ^0.10.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-05-10
- 1.0.0 — 2018-04-04
- 0.0.1 — 2018-04-04

## README

# phash-im

> Perceptual image hashing via [imagemagick](http://www.fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/index.html).

[![NPM](https://img.shields.io/npm/v/phash-im.svg)](https://www.npmjs.com/package/phash-im) [![Build Status](https://travis-ci.org/transitive-bullshit/phash-im.svg?branch=master)](https://travis-ci.org/transitive-bullshit/phash-im) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](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<Array<Number>>`

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<Number>`

Computes the L2 norm of the two hashes returnd by `phash.compute` (sum of squared differences).

#### hash1

Type: `Array<Number>`
**Required**

Perceptual hash of first image.

#### hash2

Type: `Array<Number>`
**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)

---
_Source: https://npm.io/package/phash-im · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
