1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-16 10:54:02 +02:00

Add QuantizeColorsModifier tests

This commit is contained in:
Oliver Vogel
2023-12-16 14:37:24 +01:00
parent 516c6aa08f
commit 68f2bb19ce
2 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Modifiers\QuantizeColorsModifier;
use Intervention\Image\Tests\TestCase;
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
/**
* @requires extension gd
* @covers \Intervention\Image\Modifiers\QuantizeColorsModifier
*/
class QuantizeColorsModifierTest extends TestCase
{
use CanCreateGdTestImage;
public function testColorChange(): void
{
$image = $this->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);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
use Intervention\Image\Modifiers\QuantizeColorsModifier;
use Intervention\Image\Tests\TestCase;
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
/**
* @requires extension imagick
* @covers \Intervention\Image\Modifiers\QuantizeColorsModifier
*/
class QuantizeColorsModifierTest extends TestCase
{
use CanCreateImagickTestImage;
public function testColorChange(): void
{
$image = $this->readTestImage('gradient.bmp');
$this->assertEquals(15, $image->core()->native()->getImageColors());
$image->modify(new QuantizeColorsModifier(4));
$this->assertEquals(4, $image->core()->native()->getImageColors());
}
}