machinateur/imagickompare

A little PHP function that can compare PDFs and images using the Imagick PHP extension.

1.0.0 2024-10-26 15:54 UTC

This package is auto-updated.

Last update: 2024-10-26 15:58:27 UTC


README

A little PHP function that can compare PDFs and images using the Imagick PHP extension.

Requirements

  • At least PHP >=7.4 is required
    • Extension ext-imagick is required

Installation

composer require machinateur/imagickompare

Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

// simply compare two files (pdf, png, etc.)
$diffPercentage = \compare_with_imagick('/path/to/control-file', '/path/to/compare-file');
// or define a resolution
$diffPercentage = \compare_with_imagick('/path/to/control-file', '/path/to/compare-file', [100, 100]);
// and define a fuzziness for diff metrics
$diffPercentage = \compare_with_imagick('/path/to/control-file', '/path/to/compare-file', fuzziness: 5);
// the merged file can be saved as well, when passing an open file handle
$diffPercentage = \compare_with_imagick('/path/to/control-file', '/path/to/compare-file', fh: $fh = \fopen('php://temp'));

Tests

There are no tests for this library as of now.

I have used it in two of my projects (the-printe, php-qpdf-ffi) to assess PDF file differences in their tests.

License

It's MIT.