From b5cbff3a8968b1a621e494fb609a54388ef40954 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 21 Oct 2023 09:25:36 +0200 Subject: [PATCH] Remove remaining toRgb() calls --- src/Colors/Rgb/Color.php | 5 ---- src/Drivers/Gd/Traits/CanHandleColors.php | 5 ++-- .../Imagick/Decoders/BinaryImageDecoder.php | 1 + src/Interfaces/ColorInterface.php | 10 +++---- tests/Colors/Rgb/ColorTest.php | 6 ----- tests/Drivers/Gd/ImageTest.php | 27 +++++-------------- tests/TestCase.php | 3 ++- 7 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/Colors/Rgb/Color.php b/src/Colors/Rgb/Color.php index 1a5723c5..3ce1313b 100644 --- a/src/Colors/Rgb/Color.php +++ b/src/Colors/Rgb/Color.php @@ -76,11 +76,6 @@ class Color implements ColorInterface ); } - public function toRgb(): self - { - return $this; - } - public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface { $colorspace = match (true) { diff --git a/src/Drivers/Gd/Traits/CanHandleColors.php b/src/Drivers/Gd/Traits/CanHandleColors.php index ecfa1dd4..938efdfc 100644 --- a/src/Drivers/Gd/Traits/CanHandleColors.php +++ b/src/Drivers/Gd/Traits/CanHandleColors.php @@ -3,6 +3,7 @@ namespace Intervention\Image\Drivers\Gd\Traits; use Intervention\Image\Colors\Rgb\Color; +use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Interfaces\ColorInterface; trait CanHandleColors @@ -33,9 +34,9 @@ trait CanHandleColors * @param ColorInterface $color * @return int */ - public function colorToInteger(ColorInterface $color): int + public function colorToInteger(Color $color): int { - $color = $color->toRgb(); + $color = $color->convertTo(Colorspace::class); $r = $color->red()->value(); $g = $color->green()->value(); diff --git a/src/Drivers/Imagick/Decoders/BinaryImageDecoder.php b/src/Drivers/Imagick/Decoders/BinaryImageDecoder.php index ac4f1488..886f65eb 100644 --- a/src/Drivers/Imagick/Decoders/BinaryImageDecoder.php +++ b/src/Drivers/Imagick/Decoders/BinaryImageDecoder.php @@ -25,6 +25,7 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface $imagick = new Imagick(); $imagick->readImageBlob($input); $imagick = $imagick->coalesceImages(); + // $imagick->transformImageColorspace(Imagick::COLORSPACE_RGB); $image = new Image($imagick); $image->setLoops($imagick->getImageIterations()); diff --git a/src/Interfaces/ColorInterface.php b/src/Interfaces/ColorInterface.php index 6ba4cafe..1594b857 100644 --- a/src/Interfaces/ColorInterface.php +++ b/src/Interfaces/ColorInterface.php @@ -2,16 +2,14 @@ namespace Intervention\Image\Interfaces; -use Intervention\Image\Colors\Rgb\Color; - interface ColorInterface { - public function toRgb(): Color; - public function toArray(): array; - public function toString(): string; - public function toHex(): string; public function __toString(): string; + public function toString(): string; + public function toArray(): array; + public function toHex(): string; public function channels(): array; + public function channel(string $classname): ColorChannelInterface; public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface; public function isGreyscale(): bool; } diff --git a/tests/Colors/Rgb/ColorTest.php b/tests/Colors/Rgb/ColorTest.php index 131dcef7..bcbbe53a 100644 --- a/tests/Colors/Rgb/ColorTest.php +++ b/tests/Colors/Rgb/ColorTest.php @@ -73,10 +73,4 @@ class ColorTest extends TestCase $color = new Color(181, 55, 23); $this->assertEquals('rgb(181, 55, 23)', (string) $color); } - - public function testToRgb(): void - { - $color = new Color(181, 55, 23); - $this->assertInstanceOf(Color::class, $color->toRgb()); - } } diff --git a/tests/Drivers/Gd/ImageTest.php b/tests/Drivers/Gd/ImageTest.php index a878443b..cd4b7031 100644 --- a/tests/Drivers/Gd/ImageTest.php +++ b/tests/Drivers/Gd/ImageTest.php @@ -96,21 +96,15 @@ class ImageTest extends TestCase { $color = $this->image->pickColor(0, 0); $this->assertInstanceOf(Color::class, $color); - $this->assertEquals(255, $color->toRgb()->red()->value()); - $this->assertEquals(0, $color->toRgb()->green()->value()); - $this->assertEquals(0, $color->toRgb()->blue()->value()); + $this->assertEquals([255, 0, 0, 255], $color->toArray()); $color = $this->image->pickColor(0, 0, 1); $this->assertInstanceOf(Color::class, $color); - $this->assertEquals(0, $color->toRgb()->red()->value()); - $this->assertEquals(255, $color->toRgb()->green()->value()); - $this->assertEquals(0, $color->toRgb()->blue()->value()); + $this->assertEquals([0, 255, 0, 255], $color->toArray()); $color = $this->image->pickColor(0, 0, 2); $this->assertInstanceOf(Color::class, $color); - $this->assertEquals(0, $color->toRgb()->red()->value()); - $this->assertEquals(0, $color->toRgb()->green()->value()); - $this->assertEquals(255, $color->toRgb()->blue()->value()); + $this->assertEquals([0, 0, 255, 255], $color->toArray()); $color = $this->image->pickColor(0, 0, 3); $this->assertNull($color); @@ -121,17 +115,8 @@ class ImageTest extends TestCase $colors = $this->image->pickColors(0, 0); $this->assertInstanceOf(Collection::class, $colors); $this->assertCount(3, $colors); - - $this->assertEquals(255, $colors->get(0)->toRgb()->red()->value()); - $this->assertEquals(0, $colors->get(0)->toRgb()->green()->value()); - $this->assertEquals(0, $colors->get(0)->toRgb()->blue()->value()); - - $this->assertEquals(0, $colors->get(1)->toRgb()->red()->value()); - $this->assertEquals(255, $colors->get(1)->toRgb()->green()->value()); - $this->assertEquals(0, $colors->get(1)->toRgb()->blue()->value()); - - $this->assertEquals(0, $colors->get(2)->toRgb()->red()->value()); - $this->assertEquals(0, $colors->get(2)->toRgb()->green()->value()); - $this->assertEquals(255, $colors->get(2)->toRgb()->blue()->value()); + $this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray()); + $this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray()); + $this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray()); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index cfd60927..f73c069c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,6 +3,7 @@ namespace Intervention\Image\Tests; use Intervention\Image\Colors\Rgb\Color; +use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Interfaces\ColorInterface; use Mockery\Adapter\Phpunit\MockeryTestCase; @@ -26,6 +27,6 @@ abstract class TestCase extends MockeryTestCase protected function assertTransparency(ColorInterface $color) { $this->assertInstanceOf(Color::class, $color); - $this->assertEquals(0, $color->toRgb()->alpha()->value()); + $this->assertEquals(0, $color->convertTo(Colorspace::class)->alpha()->value()); } }