# imagehash-web

> [![npm](https://img.shields.io/npm/v/imagehash-web)](https://www.npmjs.com/package/imagehash-web)

Latest version **3.1.1** (published 2024-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install imagehash-web
pnpm add imagehash-web
yarn add imagehash-web
bun add imagehash-web
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2024-12-09 |
| First published | 2023-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 378.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Maintainers | simon987 |

## Links

- npm: https://www.npmjs.com/package/imagehash-web
- Repository: https://github.com/simon987/imagehash-web
- Issues: https://github.com/simon987/imagehash-web/issues
- npm.io page: https://npm.io/package/imagehash-web

## Dependencies (2)

- [pica](https://npm.io/package/pica.md) ^9.0.1
- [canvas](https://npm.io/package/canvas.md) ^2.11.2

## Recent versions

- 3.1.1 (latest) — 2024-12-09
- 3.0.1 — 2023-06-18
- 3.0.0 — 2023-06-18
- 2.0.5 — 2023-06-15
- 2.0.1 — 2023-06-14
- 2.0.0 — 2023-06-14
- 1.1.0 — 2023-06-14
- 1.0.5 — 2023-06-13
- 1.0.4 — 2023-06-12
- 1.0.3 — 2023-06-11
- 1.0.2 — 2023-06-11
- 1.0.1 — 2023-06-11
- 1.0.0 — 2023-06-11

## README

# imagehash-web

[![npm](https://img.shields.io/npm/v/imagehash-web)](https://www.npmjs.com/package/imagehash-web)

Javascript implementation of various image hashing algorithms.

```bash
npm install imagehash-web
```

The methods used to compute the image hashes
the same as the `imagehash` python library. Due to
some slight differences in the downsampling algorithm of
your browser vs Pillow, the final image hashes are not
always exactly the same as the reference library.

Implemented algorithms:

* `ahash` Average hash
* `dhash` Difference hash
* `phash` Perceptual hash
* `whash` Wavelet hash
* `cropResistantHash` Crop resistant hash

### Example usage (browser)

```html

<script src="https://unpkg.com/imagehash-web/dist/imagehash-web.min.js"></script>
<script>
    const im = document.getElementById("my-image");

    const precomputed = ImageHash.fromHexString("5dbfb5310a81a361")
    
    phash(im, 8).then(hash => {
        console.log(hash.hammingDistance(precomputed));
    });
</script>
```

### Example usage (NodeJS)

```javascript
import {loadImage} from "canvas";
import {phash, ImageHash} from "imagehash-web";

const im = await loadImage("./my_image.jpg");

const hash = await phash(im, 8);
const precomputed = ImageHash.fromHexString("5dbfb5310a81a361")

console.log(hash.hammingDistance(precomputed));
```

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