PHPackages                             jenssegers/imagehash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. jenssegers/imagehash

ActiveLibrary[Image &amp; Media](/categories/media)

jenssegers/imagehash
====================

Perceptual image hashing for PHP

v0.11.0(8mo ago)2.1k2.2M—2.4%177[36 issues](https://github.com/jenssegers/imagehash/issues)[3 PRs](https://github.com/jenssegers/imagehash/pulls)4MITPHPPHP ^8.2CI passing

Since Dec 5Pushed 8mo ago66 watchersCompare

[ Source](https://github.com/jenssegers/imagehash)[ Packagist](https://packagist.org/packages/jenssegers/imagehash)[ Docs](https://github.com/jenssegers/imagehash)[ GitHub Sponsors](https://github.com/jenssegers)[ Fund](https://tidelift.com/funding/github/packagist/jenssegers/imagehash)[ RSS](/packages/jenssegers-imagehash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (18)Used By (4)

ImageHash
=========

[](#imagehash)

[![Latest Stable Version](https://camo.githubusercontent.com/f9eaede2108106a4fb4284ce2497711d2c642c808270168d19676ede8e1b1c39/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a656e737365676572732f696d616765686173682e737667)](https://packagist.org/packages/jenssegers/imagehash) [![Build Status](https://camo.githubusercontent.com/2e21bc9cfba54118068dbca80263e35f2858881e6d63cef52c18c3d18021d3bf/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6a656e737365676572732f696d616765686173682e737667)](https://travis-ci.org/jenssegers/imagehash) [![Coverage Status](https://camo.githubusercontent.com/c3d5f57bc1b7a584fb4972ee63ef11a6292464177dde564707e49079c977fd75/687474703a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a656e737365676572732f696d616765686173682e737667)](https://coveralls.io/r/jenssegers/imagehash) [![Donate](https://camo.githubusercontent.com/d47cdb766a100070d38a702d9c7760ccc8052063484e1478a26bcd16680d33af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d70617970616c2d626c75652e737667)](https://www.paypal.me/jenssegers)

> A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output, perceptual hashes are "close" to one another if the features are similar.

[![](https://camo.githubusercontent.com/842cb8a7f05910306c4e874671503390c1c9f9ae2edac2ff68aabdc8ee50b534/68747470733a2f2f6a656e737365676572732e636f6d2f7374617469632f6d656469612f66696e6765727072696e742e706e67)](https://camo.githubusercontent.com/842cb8a7f05910306c4e874671503390c1c9f9ae2edac2ff68aabdc8ee50b534/68747470733a2f2f6a656e737365676572732e636f6d2f7374617469632f6d656469612f66696e6765727072696e742e706e67)

Perceptual hashes are a different concept compared to cryptographic hash functions like MD5 and SHA1. With cryptographic hashes, the hash values are random. The data used to generate the hash acts like a random seed, so the same data will generate the same result, but different data will create different results. Comparing two SHA1 hash values really only tells you two things. If the hashes are different, then the data is different. And if the hashes are the same, then the data is likely the same. In contrast, perceptual hashes can be compared -- giving you a sense of similarity between the two data sets.

This code was inspired/based on:

-
-
-
-
-
-

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- The [gd](http://php.net/manual/en/book.image.php) or [imagick](http://php.net/manual/en/book.imagick.php) extension
- Optionally, install the [GMP](http://php.net/manual/en/book.gmp.php) extension for faster fingerprint comparisons

Installation
------------

[](#installation)

*This package has not reached a stable version yet, backwards compatibility may be broken between 0.x releases. Make sure to lock your version if you intend to use this in production!*

Install using composer:

```
composer require jenssegers/imagehash

```

Usage
-----

[](#usage)

The library comes with 4 built-in hashing implementations:

- `Jenssegers\ImageHash\Implementations\AverageHash` - Hash based the average image color
- `Jenssegers\ImageHash\Implementations\DifferenceHash` - Hash based on the previous pixel
- `Jenssegers\ImageHash\Implementations\BlockHash` - Hash based on blockhash.io **Still under development**
- `Jenssegers\ImageHash\Implementations\PerceptualHash` - The original pHash **Still under development**

Choose one of these implementations. If you don't know which one to use, try the `DifferenceHash` implementation. Some implementations allow some configuration, be sure to check the constructor.

```
use Jenssegers\ImageHash\ImageHash;
use Jenssegers\ImageHash\Implementations\DifferenceHash;

$hasher = new ImageHash(new DifferenceHash());
$hash = $hasher->hash('path/to/image.jpg');

echo $hash;
// or
echo $hash->toHex();
```

The resulting `Hash` object, is a hexadecimal image fingerprint that can be stored in your database once calculated. The hamming distance is used to compare two image fingerprints for similarities. Low distance values will indicate that the images are similar or the same, high distance values indicate that the images are different. Use the following method to detect if images are similar or not:

```
$distance = $hasher->distance($hash1, $hash2);
// or
$distance = $hash1->distance($hash2);
```

Equal images will not always have a distance of 0, so you will need to decide at which distance you will evaluate images as equal. For the image set that I tested, a max distance of 5 was acceptable. But this will depend on the implementation, the images and the number of images. For example; when comparing a small set of images, a lower maximum distances should be acceptable as the chances of false positives are quite low. If however you are comparing a large amount of images, 5 might already be too much.

The `Hash` object can return the internal binary hash in a couple of different format:

```
echo $hash->toHex(); // 7878787c7c707c3c
echo $hash->toBits(); // 0111100001111000011110000111110001111100011100000111110000111100
echo $hash->toInt(); // 8680820757815655484
echo $hash->toBytes(); // "\x0F\x07ƒƒ\x03\x0F\x07\x00"
```

Choose your preference for storing your hashes in your database. If you want to reconstruct a `Hash` object from a previous calculated value, use:

```
$hash = Hash::fromHex('7878787c7c707c3c');
$hash = Hash::fromBin('0111100001111000011110000111110001111100011100000111110000111100');
$hash = Hash::fromInt('8680820757815655484');
```

Demo
----

[](#demo)

These images are similar:

[![Equals1](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/forest/forest-high.jpg)](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/forest/forest-high.jpg)[![Equals2](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/forest/forest-copyright.jpg)](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/forest/forest-copyright.jpg)

```
Image 1 hash: 3c3e0e1a3a1e1e1e (0011110000111110000011100001101000111010000111100001111000011110)
Image 2 hash: 3c3e0e3e3e1e1e1e (0011110000111110000011100011111000111110000111100001111000011110)
Hamming distance: 3

```

These images are different:

[![Equals1](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/office/tumblr_ndyfnr7lk21tubinno1_1280.jpg)](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/office/tumblr_ndyfnr7lk21tubinno1_1280.jpg)[![Equals2](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/office/tumblr_ndyfq386o41tubinno1_1280.jpg)](https://raw.githubusercontent.com/jenssegers/imagehash/master/tests/images/office/tumblr_ndyfq386o41tubinno1_1280.jpg)

```
Image 1 hash: 69684858535b7575 (0010100010101000101010001010100010101011001010110101011100110111)
Image 2 hash: e1e1e2a7bbaf6faf (0111000011110000111100101101001101011011011101010011010101001111)
Hamming distance: 32

```

Security contact information
----------------------------

[](#security-contact-information)

To report a security vulnerability, follow [these steps](https://tidelift.com/security).

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance60

Regular maintenance activity

Popularity68

Solid adoption and visibility

Community38

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~246 days

Recently: every ~464 days

Total

17

Last Release

243d ago

PHP version history (6 changes)v0.1.0PHP &gt;=5.4.0

v0.6.0PHP ^5.6|^7.0

v0.7.0PHP ^7.0

v0.8.0PHP ^7.1|^8.0

v0.10.0PHP ^8.1

v0.11.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/91980fbd02c3e65e0b2ec1c65e4ca0131f1bbc3929a0a11a7f4f12db5f2036e3?d=identicon)[jenssegers](/maintainers/jenssegers)

---

Top Contributors

[![jenssegers](https://avatars.githubusercontent.com/u/194377?v=4)](https://github.com/jenssegers "jenssegers (116 commits)")[![lstrojny](https://avatars.githubusercontent.com/u/79707?v=4)](https://github.com/lstrojny "lstrojny (4 commits)")[![artyuum](https://avatars.githubusercontent.com/u/17199757?v=4)](https://github.com/artyuum "artyuum (4 commits)")[![pataar](https://avatars.githubusercontent.com/u/3403851?v=4)](https://github.com/pataar "pataar (3 commits)")[![danog](https://avatars.githubusercontent.com/u/7339644?v=4)](https://github.com/danog "danog (3 commits)")[![klermonte](https://avatars.githubusercontent.com/u/2529340?v=4)](https://github.com/klermonte "klermonte (3 commits)")[![mcuelenaere](https://avatars.githubusercontent.com/u/1682432?v=4)](https://github.com/mcuelenaere "mcuelenaere (2 commits)")[![winkelement](https://avatars.githubusercontent.com/u/3525191?v=4)](https://github.com/winkelement "winkelement (1 commits)")[![wouterds](https://avatars.githubusercontent.com/u/1210628?v=4)](https://github.com/wouterds "wouterds (1 commits)")[![AliveShiro](https://avatars.githubusercontent.com/u/1019801?v=4)](https://github.com/AliveShiro "AliveShiro (1 commits)")[![xanily](https://avatars.githubusercontent.com/u/1019801?v=4)](https://github.com/xanily "xanily (1 commits)")[![bogdanstoik](https://avatars.githubusercontent.com/u/973899?v=4)](https://github.com/bogdanstoik "bogdanstoik (1 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")[![ivqonsanada](https://avatars.githubusercontent.com/u/36329890?v=4)](https://github.com/ivqonsanada "ivqonsanada (1 commits)")[![mallardduck](https://avatars.githubusercontent.com/u/619938?v=4)](https://github.com/mallardduck "mallardduck (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![samwilson](https://avatars.githubusercontent.com/u/213655?v=4)](https://github.com/samwilson "samwilson (1 commits)")

---

Tags

hashimageimage-hashperceptual-hasheshashimagehashperceptualdhashahashphashimage hash

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jenssegers-imagehash/health.svg)

```
[![Health](https://phpackages.com/badges/jenssegers-imagehash/health.svg)](https://phpackages.com/packages/jenssegers-imagehash)
```

###  Alternatives

[league/glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k51.2M116](/packages/league-glide)[yzalis/identicon

Generate unique identicon avatars from any string

5901.1M21](/packages/yzalis-identicon)[intervention/image-laravel

Laravel Integration of Intervention Image

1536.5M102](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[lasserafn/php-initial-avatar-generator

A package to generate avatars with initials for PHP

4374.2M13](/packages/lasserafn-php-initial-avatar-generator)[simonhamp/the-og

A minimalist OpenGraph Image Generator for PHP

29340.0k](/packages/simonhamp-the-og)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
