bdelespierre/php-phash
pHash implementation in PHP
Maintainers
v1.0.1
2020-08-20 22:23 UTC
Requires
- php: ~7.3
- intervention/image: ^2.5
- symfony/console: ^5.1
Requires (Dev)
- phpunit/phpunit: ^9.3
Suggests
- ext-gd: to use GD library based image processing.
- ext-imagick: to use Imagick based image processing.
Provides
None
Conflicts
None
Replaces
None
MIT 06fa96505fe7c01e7592134e7ef2c21e9fc74488
- Benjamin Delespierre <benjamin.delespierre.woop@gmail.com>
This package is auto-updated.
Last update: 2026-06-04 22:16:46 UTC
README
👁 Latest Version on Packagist
👁 Build Status
👁 Quality Score
👁 Total Downloads
Computes the pHash (Perceptive Hash) of an image to compare images.
Installation
You can install the package via composer:
composer require bdelespierre/php-phash
Usage
vendor/bin/phash generate <image> vendor/bin/phash compare <image1> <image2>
require "vendor/autoload.php"; use Bdelespierre\PhpPhash\PHash; use Intervention\Image\ImageManager; $manager = new ImageManager(['driver' => 'imagick']); $phash = new PHash($manager); $hash = $phash->hash(new \SplFileInfo("image.jpg")); $bash_hex = base_convert($bits, 2, 16); echo $base_hex; // ffffef0001900000
Compare 2 hashes using Hamming Distance
$hash1 = $phash->hash(new \SplFileInfo("image1.jpg")); $hash2 = $phash->hash(new \SplFileInfo("image2.jpg")); $dist = 0; for ($i = 0; $i < $size ** 2; $i++) { if ($hash1[$i] != $hash2[$i]) { $dist++; } } echo "Hamming distance is: {$dist}";
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email benjamin.delespierre@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
