(PECL imagick 2.0.0)

Imagick::compareImagesCompares an image to a reconstructed image


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

Returns an array containing a reconstructed image and the difference between images.

Список параметров


An image to compare to.


Provide a valid metric type constant. Refer to this list of metric constants.

Возвращаемые значения

В случае успешной работы возвращает TRUE.


Вызывает ImagickException при ошибке.


Пример #1 Using Imagick::compareImages():

Compare images and display the reconstructed image


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

$result $image1->compareImages($image2Imagick::METRIC_MEANSQUAREERROR);

header("Content-Type: image/png");



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:

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

// set the fuzz factor (must be done BEFORE reading in the images)

// read in the images

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

// print out the result
echo "The image comparison 2% Fuzz factor is: " $result[1];
2014-05-01 21:09:50
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.
2014-08-12 17:58:11

    Поддержать сайт на родительском проекте КГБ