public function ImageEffectsTestBase::assertColorsAreClose in Image Effects 8.3
Same name and namespace in other branches
- 8 tests/src/Functional/ImageEffectsTestBase.php \Drupal\Tests\image_effects\Functional\ImageEffectsTestBase::assertColorsAreClose()
- 8.2 tests/src/Functional/ImageEffectsTestBase.php \Drupal\Tests\image_effects\Functional\ImageEffectsTestBase::assertColorsAreClose()
Assert two colors are close by RGBA within a tolerance.
Very basic, just compares the sum of the squared differences for each of the R, G, B, A components of two colors against a 'tolerance' value.
Parameters
int[] $actual: The actual RGBA array.
int[] $expected: The expected RGBA array.
int $tolerance: The acceptable difference between the colors.
6 calls to ImageEffectsTestBase::assertColorsAreClose()
- AutoOrientTest::testAutoOrientAllTags in tests/
src/ Functional/ Effect/ AutoOrientTest.php - Auto Orientation effect test, all EXIF orientation tags.
- ContrastTest::testContrastEffect in tests/
src/ Functional/ Effect/ ContrastTest.php - Contrast effect test.
- GaussianBlurTest::testGaussianBlurEffect in tests/
src/ Functional/ Effect/ GaussianBlurTest.php - Gaussian blur effect test.
- ImageEffectsTestBase::assertColorsAreEqual in tests/
src/ Functional/ ImageEffectsTestBase.php - Assert two colors are equal by RGBA.
- SetTransparentColorTest::testSetTransparentColorEffect in tests/
src/ Functional/ Effect/ SetTransparentColorTest.php - Set transparent color effect test.
File
- tests/
src/ Functional/ ImageEffectsTestBase.php, line 301
Class
- ImageEffectsTestBase
- Base test class for image_effects tests.
Namespace
Drupal\Tests\image_effects\FunctionalCode
public function assertColorsAreClose(array $actual, array $expected, $tolerance) : void {
// Fully transparent colors are equal, regardless of RGB.
if ($actual[3] == 127 && $expected[3] == 127) {
return;
}
$distance = pow($actual[0] - $expected[0], 2) + pow($actual[1] - $expected[1], 2) + pow($actual[2] - $expected[2], 2) + pow($actual[3] - $expected[3], 2);
$this
->assertLessThanOrEqual($tolerance, $distance, "Actual: {" . implode(',', $actual) . "}, Expected: {" . implode(',', $expected) . "}, Distance: " . $distance . ", Tolerance: " . $tolerance);
}