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()); + } +}