# imgphash

> Provide an image class that is able to calculate similarity to other images using the phash value

Latest version **0.6.0** (published 2026-03-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install imgphash
pnpm add imgphash
yarn add imgphash
bun add imgphash
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2026-03-01 |
| First published | 2022-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Victor Martinez <jaster.victor@gmail.com> |
| Maintainers | jasterv |
| Keywords | javascript, phash, hashing, images, image-phash |

## Links

- npm: https://www.npmjs.com/package/imgphash
- Repository: https://github.com/JasterV/imgphash
- Homepage: https://github.com/JasterV/imgphash#readme
- Issues: https://github.com/JasterV/imgphash/issues
- npm.io page: https://npm.io/package/imgphash

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^1.13.6
- [@canvas/image](https://npm.io/package/@canvas/image.md) ^2.0.0
- [blockhash-core](https://npm.io/package/blockhash-core.md) ^0.1.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

- 0.6.0 (latest) — 2026-03-01
- 0.5.1 — 2024-06-03
- 0.5.0 — 2024-04-04
- 0.4.0 — 2022-05-18
- 0.3.2 — 2022-03-22
- 0.3.1 — 2022-03-21
- 0.2.0 — 2022-03-21
- 0.1.1 — 2022-03-21
- 0.1.0 — 2022-03-21

## README

<h1 align="center">Welcome to imgphash 👋</h1>
<p>
  <img alt="Version" src="https://img.shields.io/badge/version-0.5.0-blue.svg?cacheSeconds=2592000" />
  <a href="https://github.com/JasterV/imgphash#readme" target="_blank">
    <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
  </a>
  <a href="https://github.com/JasterV/imgphash/graphs/commit-activity" target="_blank">
    <img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" />
  </a>
  <a href="https://github.com/JasterV/imgphash/blob/main/LICENSE" target="_blank">
    <img alt="License: MIT" src="https://img.shields.io/github/license/JasterV/imgphash" />
  </a>
</p>

> Provide an image class that is able to calculate similarity to other images using the phash value

### 🏠 [Homepage](https://github.com/JasterV/imgphash#readme)

## Install

```sh
npm i imgphash
```

## Use

This module provides a class `HashImage` that you can use to hash an image and compare it

- Create a `HashImage` from a url

```javascript
const image = await HashImage.fromUrl(url1);
```

- Create a `HashImage` from a Node buffer

```javascript
const image = new HashImage(buffer);
```

- Get the hash of 2 images and compare them

```javascript
const image1 = await HashImage.fromUrl(url1);
const image2 = await HashImage.fromUrl(url2);
const hash1 = await image1.phash(); // PHash instance
const hash2 = await image2.phash();
const similarity = hash1.compare(hash2);
```

> The hash function returns an instance of `PHash`

- Or just compare 2 image objects, this is going to internally calculate their hash and use it

```javascript
const image1 = await HashImage.fromUrl(url1);
const image2 = await HashImage.fromUrl(url2);
const similarity = await image1.compare(image2);
```

> All the comparisons return a value between 0 and 1.
> 0 meaning that the images are completely different and 1 meaning they are exactly the same image

## Author

👤 **Victor Martinez <jaster.victor@gmail.com>**

## 🤝 Contributing

Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/JasterV/imgphash/issues).

## Show your support

Give a ⭐️ if this project helped you!

## 📝 License

Copyright © 2022 [Victor Martinez <jaster.victor@gmail.com>](https://github.com/JasterV).<br />
This project is [MIT](https://github.com/JasterV/imgphash/blob/main/LICENSE) licensed.

---

_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_

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