PHP code example of spatie / pixelmatch-php

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

    

spatie / pixelmatch-php example snippets


use Spatie\Pixelmatch\Pixelmatch;

$pixelmatch = Pixelmatch::new("path/to/file1.png", "path/to/file2.png");

$pixelmatch->matchedPixelPercentage(); // returns a float, for example 97.5
$pixelmatch->mismatchedPixelPercentage(); // returns a float, for example 2.5

use Spatie\Pixelmatch\Pixelmatch;

$pixelmatch = Pixelmatch::new("path/to/file1.png", "path/to/file2.png");

$pixelmatch->matchedPixelPercentage(); // returns a float, for example 97.5
$pixelmatch->mismatchedPixelPercentage(); // returns a float, for example 2.5

use Spatie\Pixelmatch\Pixelmatch;

$pixelmatch = Pixelmatch::new("path/to/file1.png", "path/to/file2.png");

$pixelmatch->matchedPixels(); // returns an int
$pixelmatch->mismatchedPixels(); // returns an int

use Spatie\Pixelmatch\Pixelmatch;

$pixelmatch = Pixelmatch::new("path/to/file1.png", "path/to/file2.png");
$pixelmatch->matches(); // returns a boolean
$pixelmatch->doesNotMatch(); // returns a boolean

$pixelmatch->threshold(0.05);

$pixelmatch->
bash
composer