---
application: "Intervention ImageHash"
version: "Version 0.1"
status: "beta"
---

# Intervention ImageHash

## Perceptual Image Hashing for PHP

Intervention ImageHash is an extension library to Intervention Image and provides perceptual image hashing with different strategies. Generate compact fingerprints of images and compare them to detect similar or duplicate content.

### Features

- Four built-in hashing strategies (Average, Difference, Block, Perceptual)
- Support for GD, Imagick, and libvips drivers
- Seamless integration with Intervention Image processing pipelines
- Hamming distance comparison for similarity detection
- Multiple hash format conversions
- Optional GMP extension support for faster comparisons

### What is Perceptual Image Hashing?

A perceptual hash is a fingerprint of an image derived from its visual features. Unlike cryptographic hash functions like MD5 or SHA1, which produce completely different outputs for even minor changes, perceptual hashes are "close" to one another when images are visually similar. This makes them ideal for:

- Detecting duplicate or near-duplicate images
- Finding images that have been resized, compressed, or slightly modified
- Organizing and deduplicating image collections
- Content moderation and copyright detection


### Code Example

The library provides two approaches for generating image hashes. You can use the `ImageHasher` class directly or integrate hashing into an existing Intervention Image pipeline using the `analyze()` method.

#### Using ImageHasher

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

// create hasher with driver and strategy
$hasher = new ImageHasher(new GdDriver(), new Difference());

// generate hash from image path
$hash = $hasher->hash('path/to/image.jpg');

// convert hash to hexadecimal format
echo $hash->toHex(); // "8f9e9d8b0f0f1f07"
```

#### Using Image Analyzer

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

// create image manager and decode image
$image = ImageManager::usingDriver(GdDriver::class)
    ->decodePath('path/to/image.jpg');

// generate hash using analyze method
$hash = $image->analyze(new Difference());
```

Read more on how to [install](https://imagehash.intervention.io/beta/getting-started/installation.md) the package or explore how to [build image hashes](https://imagehash.intervention.io/beta/api/hasher.md).

---

## Become a Sponsor

### Intervention ImageHash needs your help to keep the project going

Intervention ImageHash is non-commercial, open source licensed and completely free to use. The considerable
effort required to maintain and develop the software is only possible with the financial support
of sponsors. There are two ways in which you can support this project.

- Support via [GitHub Sponsors](https://github.com/sponsors/Intervention)
- Support via [Ko-Fi](https://ko-fi.com/interventionphp)