From 68f2bb19ce6954d6bb73d4ddfdb66b42710c8295 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 16 Dec 2023 14:37:24 +0100 Subject: [PATCH] Add QuantizeColorsModifier tests --- .../Modifiers/QuantizeColorsModifierTest.php | 42 +++++++++++++++++++ .../Modifiers/QuantizeColorsModifierTest.php | 24 +++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php create mode 100644 tests/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php diff --git a/tests/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php b/tests/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php new file mode 100644 index 00000000..da415cd8 --- /dev/null +++ b/tests/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php @@ -0,0 +1,42 @@ +readTestImage('gradient.bmp'); + $this->assertColorCount(15, $image); + $image->modify(new QuantizeColorsModifier(4)); + $this->assertColorCount(4, $image); + } + + private function assertColorCount(int $count, ImageInterface $image): void + { + $colors = []; + $width = $image->width(); + $height = $image->height(); + for ($x = 0; $x < $width; $x++) { + for ($y = 0; $y < $height; $y++) { + $rgb = imagecolorat($image->core()->native(), $x, $y); + $color = imagecolorsforindex($image->core()->native(), $rgb); + $color = implode('-', $color); + $colors[$color] = $color; + } + } + + $this->assertEquals(count($colors), $count); + } +} diff --git a/tests/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php b/tests/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php new file mode 100644 index 00000000..ec8731d0 --- /dev/null +++ b/tests/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php @@ -0,0 +1,24 @@ +readTestImage('gradient.bmp'); + $this->assertEquals(15, $image->core()->native()->getImageColors()); + $image->modify(new QuantizeColorsModifier(4)); + $this->assertEquals(4, $image->core()->native()->getImageColors()); + } +}