mirror of
https://github.com/Intervention/image.git
synced 2025-08-17 19:26:25 +02:00
Add QuantizeColorsModifier tests
This commit is contained in:
42
tests/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php
Normal file
42
tests/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user