Computes the pHash (Perceptive Hash) of an image to compare images.
You can install the package via composer:
composer require bdelespierre/php-phash
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}";
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email benjamin.delespierre@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.