1. Go to this page and download the library: Download sapientpro/image-comparator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sapientpro / image-comparator example snippets
use SapientPro\ImageComparator\ImageComparator;
$imageComparator = new ImageComparator()
$imageComparator->hashImage('your-images/non-existent-image.jpg'); // SapientPro\ImageComparator\ImageResourceException: Could not create an image resource from file
use SapientPro\ImageComparator\ImageComparator;
$image1 = 'https://github.com/sapientpro/image-comparator/blob/feature/phasher-implementation/tests/images/ebay-image.png?raw=true';
$image2 = 'https://github.com/sapientpro/image-comparator/blob/feature/phasher-implementation/tests/images/amazon-image.png?raw=true'
$imageComparator = new ImageComparator();
$similarity = $imageComparator->compare($image1, $image2); //default hashing without rotation
echo $similarity; //87.5
use SapientPro\ImageComparator\ImageComparator;
$image1 = 'https://github.com/sapientpro/image-comparator/blob/feature/phasher-implementation/tests/images/ebay-image2.png?raw=true';
$image2 = 'https://github.com/sapientpro/image-comparator/blob/feature/phasher-implementation/tests/images/amazon-image2.png?raw=true'
$imageComparator = new ImageComparator();
$similarity = $imageComparator->compare($image1, $image2); //default hashing without rotation
echo $similarity; //54.7
use SapientPro\ImageComparator\Enum\ImageRotationAngle;
$similarity = $imageComparator->compare($image1, $image2, ImageRotationAngle::D180); //compared image will be considered rotated by 180 degrees
echo $similarity; //95.3
use SapientPro\ImageComparator\ImageComparator;
$image1 = 'https://raw.githubusercontent.com/sapientpro/phasher/feature/phasher-implementation/tests/images/forest1.jpg';
$image2 = 'https://raw.githubusercontent.com/sapientpro/phasher/feature/phasher-implementation/tests/images/forest1-copyrighted.jpg'
$imageComparator = new ImageComparator();
$similarity = $imageComparator->detect($image1, $image2);
echo $similarity; //95.3
use SapientPro\ImageComparator\Strategy\DifferenceHashStrategy;
$imageComparator->setHashStrategy(new DifferenceHashStrategy());
$imageComparator->hashImage('image1.jpg');
use SapientPro\ImageComparator\Strategy\DifferenceHashStrategy;
$imageComparator->setHashStrategy(new DifferenceHashStrategy());
$imageComparator->compare('image1.jpg', 'image2.jpg'); // images will be hashed using difference hash algorithm and then compared
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.