krugozor / hash
PHP Compare Image (Average Hash, Simple Hash)
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 5
pkg:composer/krugozor/hash
Requires
- php: >=8.0
This package is auto-updated.
Last update: 2025-09-17 02:59:27 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
2.jpg
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
$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