function ToolkitGdTest::assertColorsAreEqual
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php \Drupal\KernelTests\Core\Image\ToolkitGdTest::assertColorsAreEqual()
- 10 core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php \Drupal\KernelTests\Core\Image\ToolkitGdTest::assertColorsAreEqual()
Assert two colors are equal by RGBA, net of full transparency.
Parameters
int[] $expected: The expected RGBA array.
int[] $actual: The actual RGBA array.
int $tolerance: The acceptable difference between the colors.
string $message: The assertion message.
1 call to ToolkitGdTest::assertColorsAreEqual()
- ToolkitGdTest::testManipulations in core/
tests/ Drupal/ KernelTests/ Core/ Image/ ToolkitGdTest.php - Tests height, width and color for the corners for the final images.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Image/ ToolkitGdTest.php, line 85
Class
- ToolkitGdTest
- Tests for the GD image toolkit.
Namespace
Drupal\KernelTests\Core\ImageCode
protected function assertColorsAreEqual(array $expected, array $actual, int $tolerance, string $message = '') : 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, $message . " - Actual: {" . implode(',', $actual) . "}, Expected: {" . implode(',', $expected) . "}, Distance: " . $distance . ", Tolerance: " . $tolerance);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.