Skip to content

PHP Compare Image (algoritm Average Hash, Simple Hash)

Notifications You must be signed in to change notification settings

Vasiliy-Makogon/CompareImage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Compare Image (algoritm Average Hash, Simple Hash)

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