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).
composer require krugozor/hash
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
$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