krugozor/hash

There is no license information available for the latest version (1.0.0) of this package.

PHP Compare Image (Average Hash, Simple Hash)

1.0.0 2024-11-16 22:48 UTC

This package is auto-updated.

Last update: 2024-12-17 01:17:36 UTC


README

A fast image comparison library for PHP 8. Get Average Hash string and detect duplicate image. Solution from nvthaovn/CompareImage was refactored (tested on PHP 8.2).

Install

composer require krugozor/hash

Example (two similar but different pictures)

1.jpg

alt text

2.jpg

alt text

include './src/AverageHash.php';

$hash1 = AverageHash::getHash('1.jpg');
$hash2 = AverageHash::getHash('2.jpg');

echo "Difference between $hash1 and $hash2: " . AverageHash::compare($hash1, $hash2);
// difference = 15

3.jpg

alt text

$hash3 = AverageHash::getHash('3.jpg');

echo "Difference between $hash1 and $hash3: " . AverageHash::compare($hash1, $hash3);
// difference = 10
// if different rates <= 10 then the images are duplicate