You are here

public function GdImageAnalysisTest::testDifference in Image Effects 8.3

Same name and namespace in other branches
  1. 8 tests/src/Unit/GdImageAnalysisTest.php \Drupal\Tests\image_effects\Unit\GdImageAnalysisTest::testDifference()
  2. 8.2 tests/src/Unit/GdImageAnalysisTest.php \Drupal\Tests\image_effects\Unit\GdImageAnalysisTest::testDifference()

Verify the difference calculation.

File

tests/src/Unit/GdImageAnalysisTest.php, line 45

Class

GdImageAnalysisTest
Tests the image analysis helper methods.

Namespace

Drupal\Tests\image_effects\Unit

Code

public function testDifference() {
  $image1 = imagecreatefrompng(__DIR__ . '/../../images/left.png');
  $image2 = imagecreatefrompng(__DIR__ . '/../../images/left.png');
  $diff = GdImageAnalysis::difference($image1, $image2);
  $this
    ->assertEquals(0, GdImageAnalysis::mean($diff));
  $this
    ->assertEquals([
    0 => 120,
    256 => 120,
    512 => 120,
  ], array_filter(GdImageAnalysis::histogram($diff)));
  $this
    ->assertEquals(1.585, round(GdImageAnalysis::entropy($diff), 3));
}