After $ im->cropImage method, $ im->subImageMatch doesn't work, before using $ im->subImageMatch, use $ im->setImagePage(0, 0, 0, 0);
The sequence is as follows:
$ im->cropImage();
$ im->setImagePage (0, 0, 0, 0);
$ im->subImageMatch()(PECL imagick 3 >= 3.3.0)
Imagick::subImageMatch — 現在の画像から部分画像を検索し、類似度画像を返す
$Imagick, array &$offset = ?, float &$similarity = ?): Imagick現在の画像から部分画像を検索し、類似度画像を返します。 完全に一致する箇所は白、まったく一致しない箇所は黒、 その中間はグレーの階調で表現されます。 オプションのパラメータ bestMatch と similarity を渡すこともできます。 この関数の呼び出し後、similarity には部分画像と元画像中の一致箇所との 類似度の「スコア」が設定されます。bestMatch には一致した領域を示す x, y, width, height の要素を持つ連想配列が格納されます。
Imagick
offset
similarity各ピクセルの類似度を表す新しい画像。
例1 Imagick::subImageMatch()
<?php
function subImageMatch($imagePath) {
$imagick = new \Imagick(realpath($imagePath));
$imagick2 = clone $imagick;
$imagick2->cropimage(40, 40, 250, 110);
$imagick2->vignetteimage(0, 1, 3, 3);
$similarity = null;
$bestMatch = null;
$comparison = $imagick->subImageMatch($imagick2, $bestMatch, $similarity);
$comparison->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
}
?>After $ im->cropImage method, $ im->subImageMatch doesn't work, before using $ im->subImageMatch, use $ im->setImagePage(0, 0, 0, 0);
The sequence is as follows:
$ im->cropImage();
$ im->setImagePage (0, 0, 0, 0);
$ im->subImageMatch()