示例#1
0
    $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);
    }
 /**
  * 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 . ".");
     }
 }