PHP 5.4.36 Released

Imagick::compareImages

(PECL imagick 2.0.0)

Imagick::compareImagesCompare une image avec une image reconstituée

Description

array Imagick::compareImages ( Imagick $compare , int $metric )

Retourne un tableau contenant l'image reconstituée et les différences entre les images.

Liste de paramètres

compare

Une image à comparer.

metric

Une constante de type de métrique. Voyez la liste des constantes de métriques.

Valeurs de retour

Returns TRUE on success.

Erreurs / Exceptions

Lance une exception ImagickException si une erreur survient.

Exemples

Exemple #1 Exemple avec Imagick::compareImages()

Compare des images et affiche l'image reconstituée

<?php

$image1 
= new imagick("image1.png");
$image2 = new imagick("image2.png");

$result $image1->compareImages($image2Imagick::METRIC_MEANSQUAREERROR);
$result[0]->setImageFormat("png");

header("Content-Type: image/png");
echo 
$result[0];

?>

add a note add a note

User Contributed Notes 2 notes

up
2
info at celeste-design dot de
4 months ago
If you get the following non-descriptive error message:

Uncaught exception 'ImagickException' with message 'Compare images failed'

Check your picture dimensions! i compared a 21x20 png to a 20x20 png which resulted in that error. Took me forever to figure out that the dimensions have to be exactly the same.
up
0
Tim K and Sam M @netflix
7 months ago
The *Absolute Error* metric is not listed as an available metric constant. However, you can still use it if needed by passing the internal constant definition for AE which is 1. This is useful when you wish to compare using a desired fuzz factor. Example:

<?php
// init the image objects
$image1 = new imagick();
$image2 = new imagick();

// set the fuzz factor (must be done BEFORE reading in the images)
$image1->SetOption('fuzz', '2%');

// read in the images
$image1->readImage("php_step29_actual.png");
$image2->readImage("php_step29_correct.png");

// compare the images using METRIC=1 (Absolute Error)
$result = $image1->compareImages($image2, 1);

// print out the result
echo "The image comparison 2% Fuzz factor is: " . $result[1];
?>
To Top