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.Imagick::compareImages
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Imagick::compareImages
Референца за `imagick.compareimages.php` со подобрена типографија и навигација.
Imagick::compareImages
(PECL imagick 2, PECL imagick 3)
Imagick::compareImages — Споредува слика со реконструирана слика
= NULL
$compare, int $metric): arrayВраќа низа што содржи реконструирана слика и разликата помеѓу сликите.
Параметри
compare-
Слика за споредба.
metric-
Обезбедете валидна константа од типот метрика. Погледнете ја оваа листа на константи за метрика.
Вратени вредности
Враќа низа што содржи реконструирана слика и разликата помеѓу сликите.
Errors/Exceptions
Фрла ImagickException при грешка.
Примери
Пример #1 Користење (PECL imagick 2, PECL imagick 3):
Споредете ги сликите и прикажете ја реконструираната слика
<?php
$image1 = new imagick("image1.png");
$image2 = new imagick("image2.png");
$result = $image1->compareImages($image2, Imagick::METRIC_MEANSQUAREERROR);
$result[0]->setImageFormat("png");
header("Content-Type: image/png");
echo $result[0];
?>Белешки од корисници 2 забелешки
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];
?>