略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::subImageMatch

2024-11-13

Imagick::subImageMatch

(PECL imagick 3 >= 3.3.0)

Imagick::subImageMatchDescription

说明

public Imagick::subImageMatch(Imagick $Imagick, array &$offset = ?, float &$similarity = ?): Imagick

Searches for a subimage in the current image and returns a similarity image such that an exact match location is completely white and if none of the pixels match, black, otherwise some gray level in-between. You can also pass in the optional parameters bestMatch and similarity. After calling the function similarity will be set to the 'score' of the similarity between the subimage and the matching position in the larger image, bestMatch will contain an associative array with elements x, y, width, height that describe the matching region.

参数

Imagick

offset

similarity

A new image that displays the amount of similarity at each pixel.

返回值

范例

示例 #1 Imagick::subImageMatch()

<?php
function subImageMatch($imagePath) {
    
$imagick = new \Imagick(realpath($imagePath));
    
$imagick2 = clone $imagick;
    
$imagick2->cropimage(4040250110);
    
$imagick2->vignetteimage(0133);

    
$similarity null;
    
$bestMatch null;
    
$comparison $imagick->subImageMatch($imagick2$bestMatch$similarity);

    
$comparison->setImageFormat('png');
    
header("Content-Type: image/png");
    echo 
$imagick->getImageBlob();
}

?>
add a noteadd a note

User Contributed Notes 1 note

up
0
inipel at ya dot ru
9 months ago
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()

官方地址:https://www.php.net/manual/en/imagick.subimagematch.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3