1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-02 18:32:56 +02:00

Fix incorrect color results after color reduction (#1410)

* Add tests to verify issue 1409
* Enable GD's ColorProcessor to resolve array color format
* Fix bug when reading colors from palette GDImage
* Add detailed type hint
This commit is contained in:
Oliver Vogel
2025-01-04 08:31:37 +01:00
committed by GitHub
parent 436460e33b
commit 1c68e5fdf4
5 changed files with 97 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ final class ColorProcessorTest extends BaseTestCase
$this->assertEquals(16725760, $result);
}
public function testNativeToColor(): void
public function testNativeToColorInteger(): void
{
$processor = new ColorProcessor();
$result = $processor->nativeToColor(16725760);
@@ -37,6 +37,17 @@ final class ColorProcessorTest extends BaseTestCase
$this->assertEquals(255, $result->channel(Alpha::class)->value());
}
public function testNativeToColorArray(): void
{
$processor = new ColorProcessor();
$result = $processor->nativeToColor(['red' => 255, 'green' => 55, 'blue' => 0, 'alpha' => 0]);
$this->assertInstanceOf(Color::class, $result);
$this->assertEquals(255, $result->channel(Red::class)->value());
$this->assertEquals(55, $result->channel(Green::class)->value());
$this->assertEquals(0, $result->channel(Blue::class)->value());
$this->assertEquals(255, $result->channel(Alpha::class)->value());
}
public function testNativeToColorInvalid(): void
{
$processor = new ColorProcessor();

View File

@@ -55,4 +55,11 @@ final class QuantizeColorsModifierTest extends GdTestCase
$this->assertEquals(count($colors), $count);
}
public function testVerifyColorValueAfterQuantization(): void
{
$image = $this->createTestImage(3, 2)->fill('f00');
$image->modify(new QuantizeColorsModifier(1));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1), 4);
}
}

View File

@@ -37,4 +37,11 @@ final class QuantizeColorsModifierTest extends ImagickTestCase
$this->expectException(InputException::class);
$image->modify(new QuantizeColorsModifier(0));
}
public function testVerifyColorValueAfterQuantization(): void
{
$image = $this->createTestImage(3, 2)->fill('f00');
$image->modify(new QuantizeColorsModifier(1));
$this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1));
}
}