PHPackages                             intervention/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. intervention/imagehash

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

intervention/imagehash
======================

Perceptual image hashing for PHP

0.1.1(1mo ago)111↓75%MITPHPPHP ^8.3CI passing

Since Jul 4Pushed 1mo agoCompare

[ Source](https://github.com/Intervention/imagehash)[ Packagist](https://packagist.org/packages/intervention/imagehash)[ Docs](https://github.com/Intervention/imagehash)[ Fund](https://paypal.me/interventionio)[ GitHub Sponsors](https://github.com/Intervention)[ RSS](/packages/intervention-imagehash/feed)WikiDiscussions develop Synced 1w ago

READMEChangelog (2)Dependencies (10)Versions (4)Used By (0)

Intervention ImageHash
======================

[](#intervention-imagehash)

Perceptual image hashing for PHP
--------------------------------

[](#perceptual-image-hashing-for-php)

[![Latest Version](https://camo.githubusercontent.com/fab6d57354e0a1891941c00fdf9ea23aeb1317c3956270e11b16572eb5711855/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e74657276656e74696f6e2f696d616765686173682e737667)](https://packagist.org/packages/intervention/imagehash)[![Build Status](https://github.com/Intervention/image/actions/workflows/run-tests.yml/badge.svg)](https://github.com/Intervention/imagehash/actions)[![Monthly Downloads](https://camo.githubusercontent.com/214d9af683d333c059ba652ffc9382b2b21d5ea2c44aae5242a4bd60f8b0ca53/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696e74657276656e74696f6e2f696d616765686173682e737667)](https://packagist.org/packages/intervention/imagehash/stats)[![Support me on Ko-fi](https://raw.githubusercontent.com/Intervention/imagehash/develop/.github/images/support.svg)](https://ko-fi.com/interventionphp)

Intervention ImageHash is an extension library to [Intervention Image](https://github.com/Intervention/image) and provides perceptual image hashing with different strategies.

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.

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

[](#installation)

Install this library using [Composer](https://getcomposer.org). Add the package with the following command:

```
composer require intervention/imagehash
```

Usage
-----

[](#usage)

### Building Hashes

[](#building-hashes)

#### Using ImageHasher

[](#using-imagehasher)

The `ImageHasher` serves as the central starting point for all hashing operations. Depending on the PHP environment, a driver must be passed to it that matches the image extension (GD, Imagick or libvips) being used. Here is also the hashing strategy defined.

The library comes with four built-in hashing strategies:

- `Intervention\ImageHash\Strategies\Average` - Hash based the average image color
- `Intervention\ImageHash\Strategies\Difference` - Hash based on the previous pixel
- `Intervention\ImageHash\Strategies\Block` - Hash based on blockhash.io
- `Intervention\ImageHash\Strategies\Perceptual` - The original pHash

Choose one of these strategies. If you don't know which one to use, try the `Difference` strategy. Some strategies allow configuration, be sure to check the constructors.

To generate hashes, the `hash()` method is used, which can read from [various image sources](https://image.intervention.io/v4/basics/instantiation#supported-image-sources) like paths, raw image data and more.

```
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\ImageHash\ImageHasher;
use Intervention\ImageHash\Strategies\Difference;

$hasher = new ImageHasher(new GdDriver(), new Difference());
$hash = $hasher->hash('path/to/image.jpg');
```

#### Using AnalyzerInterface

[](#using-analyzerinterface)

Alternatively, you can choose to use `Image::analyze()` method instead of the `ImageHasher`. This integrates more seamlessly into an existing Intervention Image processing pipeline, if you already have instances of `Intervention\Image\Interfaces\ImageInterface` - the results remain the same.

```
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\ImageHash\Strategies\Difference;

$image = ImageManager::usingDriver(GdDriver::class)
    ->decodePath('path/to/image.jpg')
    ->scale(width: 300);

$hash = $image->analyze(new Difference()); // all strategies are possible here
```

### Comparing Hashes

[](#comparing-hashes)

The resulting `Hash` object, is a hexadecimal image fingerprint that can be stored once calculated. Two fingerprints can be compared by the hamming distance 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 methods for comparisons:

```
$distance = $hash1->distance($hash2); // 12
$equals = $hash1->equals($hash2); // false
```

Perceptual hashes are a different concept compared to cryptographic hash functions like MD5 and SHA1. With cryptographic hashes, the hash values are random. Comparing two SHA1 hash values really only tells you two things. If the hashes are different, then the data is different. In contrast, perceptual hashes can be compared - giving you a sense of similarity between the two data sets.

A perceptual hash is a compact summary of visual features. Because of that, the hashes are influenced by the input images, the processing strategy and the processing pipeline and may vary with its distance to other hashes depending on these factors.

### Converting Hashes

[](#converting-hashes)

The `Hash` object can be converted to a couple of different formats:

```
echo $hash->toHex(); // "74657374"
echo $hash->toBits(); // "01110100011001010111001101110100"
echo $hash->toBytes(); // "test"
```

### Parsing Hashes

[](#parsing-hashes)

If you want to reconstruct a `Hash` object from a previous calculated value, use:

```
$hash = Hash::fromHex('74657374');
$hash = Hash::fromBits('01110100011001010111001101110100');
$hash = Hash::fromBytes('test');
```

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

[](#requirements)

- PHP 8.3 or higher
- The [GD](http://php.net/manual/en/book.image.php), [Imagick](http://php.net/manual/en/book.imagick.php) or [libvips](https://www.libvips.org) extension
- Optionally, install the [GMP](http://php.net/manual/en/book.gmp.php) extension for faster fingerprint comparisons

Demo
----

[](#demo)

These images are similar:

[![Equals1](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/tropical_high.jpg)](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/tropical_high.jpg)[![Equals2](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/tropical_watermark.jpg)](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/tropical_watermark.jpg)

```
Image 1 hash: 8f9e9d8b0f0f1f07 (1000111110011110100111011000101100001111000011110001111100000111)
Image 2 hash: 8e9e958b0f2f1f07 (1000111010011110100101011000101100001111001011110001111100000111)
Hamming distance: 3

```

These images are different:

[![Equals1](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/mountain_day.jpg)](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/mountain_day.jpg)[![Equals2](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/tropical_high.jpg)](https://raw.githubusercontent.com/Intervention/imagehash/develop/tests/images/tropical_high.jpg)

```
Image 1 hash: 6c2b58432011e38e (0110110000101011010110000100001100100000000100011110001110001110)
Image 2 hash: 8f9e9d8b0f0f1f07 (1000111110011110100111011000101100001111000011110001111100000111)
Hamming distance: 35

```

Security
--------

[](#security)

If you discover any security related issues, please email  directly.

Authors
-------

[](#authors)

This project is based on work originally developed by [Jens Segers](https://github.com/jenssegers) and released under the MIT License. Many thanks to him for sharing his code with the community, which made this fork possible.

This version is maintained by [Oliver Vogel](https://intervention.io) including modifications and improvements, but it builds directly on the solid foundation Jens created.

License
-------

[](#license)

Intervention ImageHash is licensed under the [MIT License](LICENSE).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance91

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 59.3% 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 ~1 days

Total

2

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d172b42b2c5b53e71e56589fed3fb3467234a1c266d31b697b1d7b451f4cfe8?d=identicon)[olivervogel](/maintainers/olivervogel)

---

Top Contributors

[![jenssegers](https://avatars.githubusercontent.com/u/194377?v=4)](https://github.com/jenssegers "jenssegers (115 commits)")[![olivervogel](https://avatars.githubusercontent.com/u/884642?v=4)](https://github.com/olivervogel "olivervogel (51 commits)")[![artyuum](https://avatars.githubusercontent.com/u/17199757?v=4)](https://github.com/artyuum "artyuum (4 commits)")[![lstrojny](https://avatars.githubusercontent.com/u/79707?v=4)](https://github.com/lstrojny "lstrojny (4 commits)")[![klermonte](https://avatars.githubusercontent.com/u/2529340?v=4)](https://github.com/klermonte "klermonte (3 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)")[![mcuelenaere](https://avatars.githubusercontent.com/u/1682432?v=4)](https://github.com/mcuelenaere "mcuelenaere (2 commits)")[![wouterds](https://avatars.githubusercontent.com/u/1210628?v=4)](https://github.com/wouterds "wouterds (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)")[![winkelement](https://avatars.githubusercontent.com/u/3525191?v=4)](https://github.com/winkelement "winkelement (1 commits)")

---

Tags

hashimageperceptualhashimagehashperceptualdhashahashphashimage hash

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[jenssegers/imagehash

Perceptual image hashing for PHP

2.1k2.4M9](/packages/jenssegers-imagehash)[intervention/image-laravel

Laravel Integration of Intervention Image

1589.8M227](/packages/intervention-image-laravel)[unopim/unopim

UnoPim Laravel PIM

10.8k2.5k](/packages/unopim-unopim)[code16/sharp

Laravel Content Management Framework

79466.1k10](/packages/code16-sharp)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

506520.9k31](/packages/bkwld-croppa)[october/rain

October Rain Library

1601.7M103](/packages/october-rain)

PHPackages © 2026

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