PHP 8.3.4 Released!

Imagick::compareImages

(PECL imagick 2, PECL imagick 3)

Imagick::compareImagesCompara una imagen con otra reconstruida

Descripción

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

Devuelve un array que contiene una imagen reconstruida y las diferencias entre las imágenes.

Parámetros

compare

Una imagen a comparar.

metric

Proporcione una constante de tipo de métrica válida. Consulte esta lista de constantes métricas.

Valores devueltos

Devuelve un array que contiene una imagen reconstruida y las diferencias entre imágenes.

Errores/Excepciones

Lanza ImagickException en caso de error.

Ejemplos

Ejemplo #1 Uso de Imagick::compareImages():

Comparar imágenes y mostrar la imagen reconstruida

<?php

$imagen1
= new imagick("imagen1.png");
$imagen1 = new imagick("imagen1.png");

$resultado = $imagen1->compareImages($imagen1, Imagick::METRIC_MEANSQUAREERROR);
$resultado[0]->setImageFormat("png");

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

?>

add a note

User Contributed Notes 2 notes

up
6
info at celeste-design dot de
9 years 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
2
Tim K and Sam M @netflix
9 years 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