1--TEST-- 2Test Imagick, subImageMatch 3--SKIPIF-- 4<?php 5$imageMagickRequiredVersion=0x687; 6require_once(dirname(__FILE__) . '/skipif.inc'); 7?> 8--FILE-- 9<?php 10 11function subImageMatch() { 12 $imagick = new \Imagick(); 13 $imagick->newPseudoImage(640, 480, "magick:logo"); 14 $imagick->adaptiveResizeImage(100, 100, true); 15 //This makes the test fall over on some versions of ImageMagick 16 //$imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_DEACTIVATE); 17 $imagick2 = clone $imagick; 18 $imagick2->cropimage(25, 25, 50, 50); 19 $imagick2->setImageFormat('png'); 20 21 $imagick2->setImagePage(25, 25, 0, 0); 22 $imagick2->vignetteimage(0.25, 0.75, 3, 3); 23 24 $similarity = 'not set'; 25 $bestMatch = 'not st'; 26 $comparison = $imagick->subImageMatch($imagick2, $bestMatch, $similarity); 27 28 $comparison->setImageFormat('png'); 29 $bytes = $imagick->getImageBlob(); 30 if (strlen($bytes) <= 0) { echo "Failed to generate image.";} 31 32 $version = Imagick::getVersion(); 33 if ($version['versionNumber'] >= 0x700) { 34 $expectedValue = 0.7642; 35 } 36 else { 37 $expectedValue = 0.5585; 38 } 39 40 // This doesn't work reliably - the values are not comparable across versions 41 // if (abs($expectedValue - $similarity) <= 0.005) { 42 // echo "Similarity in range\n"; 43 // } 44 // else { 45 // echo "Similarity is out of range.\n"; 46 // var_dump($similarity); 47 // } 48 49 ksort($bestMatch); 50 foreach ($bestMatch as $key => $value) { 51 echo "$key : $value\n"; 52 } 53} 54 55subImageMatch() ; 56echo "Ok"; 57?> 58 59--EXPECTF-- 60height : 25 61width : 25 62x : 50 63y : 50 64Ok