Skip to content

bdelespierre/php-phash

Repository files navigation

PHP pHash Implementation

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.

About

pHash implementation in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages