当前位置: 首页>>代码示例>>PHP>>正文


PHP imagick::compareImages方法代码示例

本文整理汇总了PHP中imagick::compareImages方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::compareImages方法的具体用法?PHP imagick::compareImages怎么用?PHP imagick::compareImages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imagick的用法示例。


在下文中一共展示了imagick::compareImages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: chmod

    $file1 = "./images/{$tag_one}/{$path_key}.png";
    $file2 = "./images/{$tag_two}/{$path_key}.png";
    chmod("./images/{$tag_one}", 0777);
    chmod("./images/{$tag_two}", 0777);
    $progress->current($path_key + 1, "Comparing between {$file1} and {$file2}");
    if (file_exists($file1) && file_exists($file2)) {
        $image1 = new imagick($file1);
        $image2 = new imagick($file2);
        $d1 = $image1->getImageGeometry();
        $w1 = $d1['width'];
        $h1 = $d1['height'];
        $d2 = $image2->getImageGeometry();
        $w2 = $d2['width'];
        $h2 = $d2['height'];
        if ($w1 == $w2 && $h1 == $h2) {
            $result = $image1->compareImages($image2, Imagick::METRIC_MEANSQUAREERROR);
            if ($result[1] > $percent) {
                $result[0]->setImageFormat("png");
                $files[] = "{$path_key}.png";
                file_put_contents("./images/output/{$path_key}.png", $result[0]);
            }
        } else {
            $files_error[] = "Images {$file1} and {$file2} have different sizes";
        }
    }
}
if (!empty($files)) {
    $climate->comment("Please check files:");
    foreach ($files as $file) {
        $climate->comment($file);
    }
开发者ID:andrew-mikhailov,项目名称:watcher,代码行数:31,代码来源:compare.php

示例2: testDisplayFundRaisingImage

 /**
  * This method will test the displayFundRaisingImage, _addGoalIndicator, _addBorder and _checkForRequiredData methods of the fundRaisingImageCreator class
  *
  * NOTE: This test is by no means an exhaustive test of every possible combination of items between these 4 methods.
  * However, in combination with all the other tests, it provides a reasonable level of testing certainty.
  *
  * NOTE: While this test doesn't detect the difference between an RGB of 35, 99, 185 and 35, 98, 185 on a 1 pixel border color,
  * it does detect differences better than nearly everyone on the planet.
  *
  * @covers fundRaisingImageCreator::displayFundRaisingImage
  * @covers fundRaisingImageCreator::_addGoalIndicator
  * @covers fundRaisingImageCreator::_addBorder
  * @covers fundRaisingImageCreator::_checkForRequiredData
  * @covers fundRaisingImageCreator::_convertPercentToAlpha
  * @covers fundRaisingImageCreator::_getGoalIndicatorHeight
  * @covers fundRaisingImageCreator::_addGoalIndicatorOverlay
  * @covers fundRaisingImageCreator::_addGoalIndicatorUnderlay
  * @covers fundRaisingImageCreator::_addGoalMetText
  * @covers fundRaisingImageCreator::_calculateFontAngle
  * @covers fundRaisingImageCreator::_calculateFontSize
  * @covers fundRaisingImageCreator::_getCachedImageLocation
  * @dataProvider dataProviderForTestDisplayFundRaisingImage
  *
  * @param array $params - An array of parameters passed in by our data provider for use in creating our test image
  */
 public function testDisplayFundRaisingImage($params)
 {
     $fundRaisingImageCreator = new fundRaisingImageCreator();
     $fundRaisingImageCreator->setFundRaisingImage($params["fundRaisingImage"]);
     $fundRaisingImageCreator->setFontLocation($params["fontLocation"]);
     $fundRaisingImageCreator->setRaisedAmount($params["raisedAmount"]);
     $fundRaisingImageCreator->setGoalAmount($params["goalAmount"]);
     $fundRaisingImageCreator->setBorderWidth($params["borderWidth"]);
     $fundRaisingImageCreator->setBorderColor($params["borderColor"]);
     $fundRaisingImageCreator->setGoalIndicatorColor($params["goalIndicatorColor"]);
     $fundRaisingImageCreator->setGoalIndicatorOpacity($params["goalIndicatorOpacity"]);
     $fundRaisingImageCreator->setGoalIndicatorType($params["goalIndicatorType"]);
     $fundRaisingImageCreator->clearErrors();
     // Any errors that occur when using the above methods have been checked for in other test methods
     $generatedImagePath = './images/generatedImage.png';
     // The following ob_* things allow us to capture an image stream created in fundRaisingImageCreator.php and write it to file
     ob_start();
     $fundRaisingImageCreator->displayFundRaisingImage();
     $objectContents = ob_get_contents();
     ob_end_clean();
     if ("" != $objectContents) {
         // If we had some errors, nothing will output, we only want to try to create an image if we've received something
         $createdImage = imagecreatefromstring($objectContents);
         imagepng($createdImage, $generatedImagePath);
     }
     if (!empty($params['expectedErrors'])) {
         // If we're expecting errors, check for the errors (nice and simple!)
         $actualErrors = $fundRaisingImageCreator->getErrors();
         $this->assertEquals($params['expectedErrors'], $actualErrors, "testDisplayFundRaisingImage case " . $params["case"] . ": We didn't receive the correct errors.");
     } else {
         $generatedImage = new imagick($generatedImagePath);
         $knownGoodImage = new imagick($params["knownCorrectImage"]);
         $result = $generatedImage->compareImages($knownGoodImage, Imagick::METRIC_UNDEFINED);
         /*
          * Now that we're done with our generated image, we'll delete it (it's good to free up system resources as quickly as possible).
          * Additionally, if we were to delete it after our assert, it may never get deleted,
          * as a php unit case stops as soon as it hits a failure.
          */
         unlink($generatedImagePath);
         /* NOTE: comparing the *exact* same image yields a compareImages result[1] of 0.866062,
          * and comparing *vastly* different images yields a compareImages result[1] of ~0.003.
          */
         $maximumImagickSimilarityValue = 0.866062;
         // Convert the "similarity" to a more human readable format (out of 100%, based on $maximumImagickSimilarityValue)
         $imageSimilarityPercent = round($result[1] / $maximumImagickSimilarityValue * 100, 4);
         $requiredSimilarityMinimumPercent = 99.99769999999999;
         $this->assertGreaterThan($requiredSimilarityMinimumPercent, $imageSimilarityPercent, "testDisplayFundRaisingImage case " . $params["case"] . ": image similarity was " . $imageSimilarityPercent . " but the required similarity minimum was " . $requiredSimilarityMinimumPercent . ".");
     }
 }
开发者ID:unshackleddynamo,项目名称:fund_raising,代码行数:74,代码来源:fundRaisingImageCreatorTest.php


注:本文中的imagick::compareImages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。