PHP code example of intervention / imagehash

1. Go to this page and download the library: Download intervention/imagehash 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/ */

    

intervention / imagehash example snippets


use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\ImageHash\ImageHasher;
use Intervention\ImageHash\Strategies\Difference;

$hasher = new ImageHasher(new GdDriver(), new Difference());
$hash = $hasher->hash('path/to/image.jpg');

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\ImageHash\Strategies\Difference;

$image = ImageManager::usingDriver(GdDriver::class)
    ->decodePath('path/to/image.jpg')
    ->scale(width: 300);

$hash = $image->analyze(new Difference()); // all strategies are possible here

$distance = $hash1->distance($hash2); // 12
$equals = $hash1->equals($hash2); // false

echo $hash->toHex(); // "74657374"
echo $hash->toBits(); // "01110100011001010111001101110100"
echo $hash->toBytes(); // "test"

$hash = Hash::fromHex('74657374');
$hash = Hash::fromBits('01110100011001010111001101110100');
$hash = Hash::fromBytes('test');