From f16b56103a6f6e04e75b32547d0e1f827b22d2e5 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 22 Oct 2023 09:12:15 +0200 Subject: [PATCH] Revert "Remove Cmyk Colors for now" This reverts commit f24a33705815b7f48351d4a157795cb064d8747b. --- src/Colors/Cmyk/Channels/Cyan.php | 55 +++++++++ src/Colors/Cmyk/Channels/Key.php | 8 ++ src/Colors/Cmyk/Channels/Magenta.php | 8 ++ src/Colors/Cmyk/Channels/Yellow.php | 8 ++ src/Colors/Cmyk/Color.php | 115 ++++++++++++++++++ src/Colors/Cmyk/Colorspace.php | 38 ++++++ .../Cmyk/Decoders/StringColorDecoder.php | 37 ++++++ src/Colors/Rgb/Color.php | 5 - src/Colors/Rgb/Colorspace.php | 11 ++ src/Drivers/Gd/InputHandler.php | 10 +- src/Drivers/Imagick/InputHandler.php | 10 +- tests/Colors/Cmyk/ChannelTest.php | 48 ++++++++ tests/Colors/Cmyk/ColorTest.php | 69 +++++++++++ tests/Colors/Cmyk/ColorspaceTest.php | 26 ++++ .../Cmyk/Decoders/StringColorDecoderTest.php | 35 ++++++ tests/Colors/Rgb/ColorTest.php | 35 ++++++ tests/Colors/Rgb/ColorspaceTest.php | 26 ++++ tests/Drivers/Gd/InputHandlerTest.php | 20 +-- tests/Drivers/Imagick/InputHandlerTest.php | 20 +-- tests/TestCase.php | 9 +- 20 files changed, 556 insertions(+), 37 deletions(-) create mode 100644 src/Colors/Cmyk/Channels/Cyan.php create mode 100644 src/Colors/Cmyk/Channels/Key.php create mode 100644 src/Colors/Cmyk/Channels/Magenta.php create mode 100644 src/Colors/Cmyk/Channels/Yellow.php create mode 100644 src/Colors/Cmyk/Color.php create mode 100644 src/Colors/Cmyk/Colorspace.php create mode 100644 src/Colors/Cmyk/Decoders/StringColorDecoder.php create mode 100644 tests/Colors/Cmyk/ChannelTest.php create mode 100644 tests/Colors/Cmyk/ColorTest.php create mode 100644 tests/Colors/Cmyk/ColorspaceTest.php create mode 100644 tests/Colors/Cmyk/Decoders/StringColorDecoderTest.php create mode 100644 tests/Colors/Rgb/ColorspaceTest.php diff --git a/src/Colors/Cmyk/Channels/Cyan.php b/src/Colors/Cmyk/Channels/Cyan.php new file mode 100644 index 00000000..213fea38 --- /dev/null +++ b/src/Colors/Cmyk/Channels/Cyan.php @@ -0,0 +1,55 @@ +value = $this->validate($value); + } + + public function value(): int + { + return $this->value; + } + + public function normalize($precision = 32): float + { + return round($this->value() / $this->max(), $precision); + } + + public function min(): int + { + return 0; + } + + public function max(): int + { + return 100; + } + + public function validate(mixed $value): mixed + { + if ($value < $this->min() || $value > $this->max()) { + throw new ColorException('CMYK color values must be in range 0-100.'); + } + + return $value; + } + + public function toString(): string + { + return (string) $this->value(); + } + + public function __toString(): string + { + return $this->toString(); + } +} diff --git a/src/Colors/Cmyk/Channels/Key.php b/src/Colors/Cmyk/Channels/Key.php new file mode 100644 index 00000000..2893d2af --- /dev/null +++ b/src/Colors/Cmyk/Channels/Key.php @@ -0,0 +1,8 @@ +channels = [ + new Cyan($c), + new Magenta($m), + new Yellow($y), + new Key($k), + ]; + } + + public static function create(mixed $input): ColorInterface + { + return (new class ([ + Decoders\StringColorDecoder::class, + ]) extends AbstractInputHandler + { + })->handle($input); + } + + public function toHex(): string + { + return $this->convertTo(RgbColorspace::class)->toHex(); + } + + public function channels(): array + { + return $this->channels; + } + + public function cyan(): ColorChannelInterface + { + return $this->channel(Cyan::class); + } + + public function magenta(): ColorChannelInterface + { + return $this->channel(Magenta::class); + } + + public function yellow(): ColorChannelInterface + { + return $this->channel(Yellow::class); + } + + public function key(): ColorChannelInterface + { + return $this->channel(Key::class); + } + + public function toArray(): array + { + return [ + $this->cyan()->value(), + $this->magenta()->value(), + $this->yellow()->value(), + $this->key()->value(), + ]; + } + + public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface + { + $colorspace = match (true) { + is_object($colorspace) => $colorspace, + default => new $colorspace(), + }; + + return $colorspace->convertColor($this); + } + + public function toString(): string + { + return sprintf( + 'cmyk(%d, %d, %d, %d)', + $this->cyan()->value(), + $this->magenta()->value(), + $this->yellow()->value(), + $this->key()->value() + ); + } + + public function isGreyscale(): bool + { + return 0 === array_sum([ + $this->cyan()->value(), + $this->magenta()->value(), + $this->yellow()->value(), + ]); + } + + public function __toString(): string + { + return $this->toString(); + } +} diff --git a/src/Colors/Cmyk/Colorspace.php b/src/Colors/Cmyk/Colorspace.php new file mode 100644 index 00000000..76ce8ea3 --- /dev/null +++ b/src/Colors/Cmyk/Colorspace.php @@ -0,0 +1,38 @@ + $this->convertRgbColor($color), + default => $color, + }; + } + + protected function convertRgbColor(RgbColor $color): CmykColor + { + $c = (255 - $color->red()->value()) / 255.0 * 100; + $m = (255 - $color->green()->value()) / 255.0 * 100; + $y = (255 - $color->blue()->value()) / 255.0 * 100; + $k = intval(round(min([$c, $m, $y]))); + + $c = intval(round($c - $k)); + $m = intval(round($m - $k)); + $y = intval(round($y - $k)); + + return new CmykColor($c, $m, $y, $k); + } +} diff --git a/src/Colors/Cmyk/Decoders/StringColorDecoder.php b/src/Colors/Cmyk/Decoders/StringColorDecoder.php new file mode 100644 index 00000000..0f05ada9 --- /dev/null +++ b/src/Colors/Cmyk/Decoders/StringColorDecoder.php @@ -0,0 +1,37 @@ +[0-9\.]+%?), ?(?P[0-9\.]+%?), ?(?P[0-9\.]+%?), ?(?P[0-9\.]+%?)\)$/i'; + if (preg_match($pattern, $input, $matches) != 1) { + throw new DecoderException('Unable to decode input'); + } + + $values = array_map(function ($value) { + return intval(round(floatval(trim(str_replace('%', '', $value))))); + }, [$matches['c'], $matches['m'], $matches['y'], $matches['k']]); + + return new Color(...$values); + } +} diff --git a/src/Colors/Rgb/Color.php b/src/Colors/Rgb/Color.php index d7117565..9cd30fb5 100644 --- a/src/Colors/Rgb/Color.php +++ b/src/Colors/Rgb/Color.php @@ -151,11 +151,6 @@ class Color implements ColorInterface return $colorspace->convertColor($this); } - /** - * Determine if the current color is fully opaque - * - * @return bool - */ public function isFullyOpaque(): bool { return $this->alpha()->value() === 255; diff --git a/src/Colors/Rgb/Colorspace.php b/src/Colors/Rgb/Colorspace.php index 4dbaae08..4c0bcb0f 100644 --- a/src/Colors/Rgb/Colorspace.php +++ b/src/Colors/Rgb/Colorspace.php @@ -2,6 +2,7 @@ namespace Intervention\Image\Colors\Rgb; +use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -10,7 +11,17 @@ class Colorspace implements ColorspaceInterface public function convertColor(ColorInterface $color): ColorInterface { return match (get_class($color)) { + CmykColor::class => $this->convertCmykColor($color), default => $color, }; } + + protected function convertCmykColor(CmykColor $color): Color + { + return new Color( + (int) (255 * (1 - $color->cyan()->normalize()) * (1 - $color->key()->normalize())), + (int) (255 * (1 - $color->magenta()->normalize()) * (1 - $color->key()->normalize())), + (int) (255 * (1 - $color->yellow()->normalize()) * (1 - $color->key()->normalize())), + ); + } } diff --git a/src/Drivers/Gd/InputHandler.php b/src/Drivers/Gd/InputHandler.php index 2cd3da3b..a23deeaa 100644 --- a/src/Drivers/Gd/InputHandler.php +++ b/src/Drivers/Gd/InputHandler.php @@ -2,10 +2,11 @@ namespace Intervention\Image\Drivers\Gd; -use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; -use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder; +use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder as RgbHexColorDecoder; +use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder as RgbStringColorDecoder; use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder; use Intervention\Image\Colors\Rgb\Decoders\TransparentColorDecoder; +use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder as CmykStringColorDecoder; use Intervention\Image\Drivers\Abstract\AbstractInputHandler; use Intervention\Image\Drivers\Gd\Decoders\ImageObjectDecoder; use Intervention\Image\Drivers\Gd\Decoders\ColorObjectDecoder; @@ -20,8 +21,9 @@ class InputHandler extends AbstractInputHandler protected array $decoders = [ ImageObjectDecoder::class, ColorObjectDecoder::class, - HexColorDecoder::class, - StringColorDecoder::class, + RgbHexColorDecoder::class, + RgbStringColorDecoder::class, + CmykStringColorDecoder::class, TransparentColorDecoder::class, HtmlColornameDecoder::class, FilePointerImageDecoder::class, diff --git a/src/Drivers/Imagick/InputHandler.php b/src/Drivers/Imagick/InputHandler.php index c41649d0..55d87055 100644 --- a/src/Drivers/Imagick/InputHandler.php +++ b/src/Drivers/Imagick/InputHandler.php @@ -2,10 +2,11 @@ namespace Intervention\Image\Drivers\Imagick; -use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; -use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder; +use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder as RgbHexColorDecoder; +use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder as RgbStringColorDecoder; use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder; use Intervention\Image\Colors\Rgb\Decoders\TransparentColorDecoder; +use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder as CmykStringColorDecoder; use Intervention\Image\Drivers\Abstract\AbstractInputHandler; use Intervention\Image\Drivers\Imagick\Decoders\ImageObjectDecoder; use Intervention\Image\Drivers\Imagick\Decoders\ColorObjectDecoder; @@ -20,8 +21,9 @@ class InputHandler extends AbstractInputHandler protected array $decoders = [ ImageObjectDecoder::class, ColorObjectDecoder::class, - HexColorDecoder::class, - StringColorDecoder::class, + RgbHexColorDecoder::class, + RgbStringColorDecoder::class, + CmykStringColorDecoder::class, TransparentColorDecoder::class, HtmlColornameDecoder::class, FilePointerImageDecoder::class, diff --git a/tests/Colors/Cmyk/ChannelTest.php b/tests/Colors/Cmyk/ChannelTest.php new file mode 100644 index 00000000..44928abf --- /dev/null +++ b/tests/Colors/Cmyk/ChannelTest.php @@ -0,0 +1,48 @@ +assertInstanceOf(Channel::class, $channel); + } + + public function testValue(): void + { + $channel = new Channel(10); + $this->assertEquals(10, $channel->value()); + } + + public function testNormalize(): void + { + $channel = new Channel(100); + $this->assertEquals(1, $channel->normalize()); + $channel = new Channel(0); + $this->assertEquals(0, $channel->normalize()); + $channel = new Channel(20); + $this->assertEquals(.2, $channel->normalize()); + } + + public function testValidate(): void + { + $this->expectException(ColorException::class); + new Channel(101); + + $this->expectException(ColorException::class); + new Channel(-1); + } +} diff --git a/tests/Colors/Cmyk/ColorTest.php b/tests/Colors/Cmyk/ColorTest.php new file mode 100644 index 00000000..5dd59c28 --- /dev/null +++ b/tests/Colors/Cmyk/ColorTest.php @@ -0,0 +1,69 @@ +assertInstanceOf(Color::class, $color); + } + + public function testChannels(): void + { + $color = new Color(10, 20, 30, 40); + $this->assertIsArray($color->channels()); + $this->assertCount(4, $color->channels()); + } + + public function testChannel(): void + { + $color = new Color(10, 20, 30, 40); + $channel = $color->channel(Cyan::class); + $this->assertInstanceOf(Cyan::class, $channel); + $this->assertEquals(10, $channel->value()); + } + + public function testCyanMagentaYellowKey(): void + { + $color = new Color(10, 20, 30, 40); + $this->assertInstanceOf(Cyan::class, $color->cyan()); + $this->assertInstanceOf(Magenta::class, $color->magenta()); + $this->assertInstanceOf(Yellow::class, $color->yellow()); + $this->assertInstanceOf(Key::class, $color->key()); + $this->assertEquals(10, $color->cyan()->value()); + $this->assertEquals(20, $color->magenta()->value()); + $this->assertEquals(30, $color->yellow()->value()); + $this->assertEquals(40, $color->key()->value()); + } + + public function testToArray(): void + { + $color = new Color(10, 20, 30, 40); + $this->assertEquals([10, 20, 30, 40], $color->toArray()); + } + + public function testNormalize(): void + { + $color = new Color(100, 50, 20, 0); + $this->assertEquals([1.0, 0.5, 0.2, 0.0], $color->normalize()); + } + + public function testToString(): void + { + $color = new Color(100, 50, 20, 0); + $this->assertEquals('cmyk(100, 50, 20, 0)', (string) $color); + } +} diff --git a/tests/Colors/Cmyk/ColorspaceTest.php b/tests/Colors/Cmyk/ColorspaceTest.php new file mode 100644 index 00000000..818269fc --- /dev/null +++ b/tests/Colors/Cmyk/ColorspaceTest.php @@ -0,0 +1,26 @@ +assertInstanceOf( + CmykColor::class, + $colorspace->convertColor( + new RgbColor(0, 0, 0) + ) + ); + } +} diff --git a/tests/Colors/Cmyk/Decoders/StringColorDecoderTest.php b/tests/Colors/Cmyk/Decoders/StringColorDecoderTest.php new file mode 100644 index 00000000..f6af4237 --- /dev/null +++ b/tests/Colors/Cmyk/Decoders/StringColorDecoderTest.php @@ -0,0 +1,35 @@ +decode('cmyk(0,0,0,0)'); + $this->assertInstanceOf(Color::class, $result); + $this->assertEquals([0, 0, 0, 0], $result->toArray()); + + $result = $decoder->decode('cmyk(0, 100, 100, 0)'); + $this->assertInstanceOf(Color::class, $result); + $this->assertEquals([0, 100, 100, 0], $result->toArray()); + + $result = $decoder->decode('cmyk(0, 100, 100, 0)'); + $this->assertInstanceOf(Color::class, $result); + $this->assertEquals([0, 100, 100, 0], $result->toArray()); + + + $result = $decoder->decode('cmyk(0%, 100%, 100%, 0%)'); + $this->assertInstanceOf(Color::class, $result); + $this->assertEquals([0, 100, 100, 0], $result->toArray()); + } +} diff --git a/tests/Colors/Rgb/ColorTest.php b/tests/Colors/Rgb/ColorTest.php index b4020c3c..69a1b4b1 100644 --- a/tests/Colors/Rgb/ColorTest.php +++ b/tests/Colors/Rgb/ColorTest.php @@ -2,6 +2,8 @@ namespace Intervention\Image\Tests\Colors\Rgb; +use Intervention\Image\Colors\Cmyk\Color as CmykColor; +use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Blue; @@ -84,4 +86,37 @@ class ColorTest extends TestCase $color = new Color(181, 55, 23); $this->assertEquals('rgb(181, 55, 23)', (string) $color); } + + public function testConvertTo(): void + { + $color = new Color(0, 0, 0); + $converted = $color->convertTo(CmykColorspace::class); + $this->assertInstanceOf(CmykColor::class, $converted); + $this->assertEquals([0, 0, 0, 100], $converted->toArray()); + + $color = new Color(255, 255, 255); + $converted = $color->convertTo(CmykColorspace::class); + $this->assertInstanceOf(CmykColor::class, $converted); + $this->assertEquals([0, 0, 0, 0], $converted->toArray()); + + $color = new Color(255, 0, 0); + $converted = $color->convertTo(CmykColorspace::class); + $this->assertInstanceOf(CmykColor::class, $converted); + $this->assertEquals([0, 100, 100, 0], $converted->toArray()); + + $color = new Color(255, 0, 255); + $converted = $color->convertTo(CmykColorspace::class); + $this->assertInstanceOf(CmykColor::class, $converted); + $this->assertEquals([0, 100, 0, 0], $converted->toArray()); + + $color = new Color(255, 255, 0); + $converted = $color->convertTo(CmykColorspace::class); + $this->assertInstanceOf(CmykColor::class, $converted); + $this->assertEquals([0, 0, 100, 0], $converted->toArray()); + + $color = new Color(255, 204, 204); + $converted = $color->convertTo(CmykColorspace::class); + $this->assertInstanceOf(CmykColor::class, $converted); + $this->assertEquals([0, 20, 20, 0], $converted->toArray()); + } } diff --git a/tests/Colors/Rgb/ColorspaceTest.php b/tests/Colors/Rgb/ColorspaceTest.php new file mode 100644 index 00000000..be7808c5 --- /dev/null +++ b/tests/Colors/Rgb/ColorspaceTest.php @@ -0,0 +1,26 @@ +assertInstanceOf( + RgbColor::class, + $colorspace->convertColor( + new CmykColor(0, 0, 0, 0) + ) + ); + } +} diff --git a/tests/Drivers/Gd/InputHandlerTest.php b/tests/Drivers/Gd/InputHandlerTest.php index c9d1335b..177213f3 100644 --- a/tests/Drivers/Gd/InputHandlerTest.php +++ b/tests/Drivers/Gd/InputHandlerTest.php @@ -2,7 +2,7 @@ namespace Intervention\Image\Tests\Drivers\Gd; -use Intervention\Image\Colors\Rgb\Color; +use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Drivers\Gd\Image; use Intervention\Image\Drivers\Gd\InputHandler; use Intervention\Image\Exceptions\DecoderException; @@ -58,37 +58,37 @@ class GdInputHandlerTest extends TestCase $handler = new InputHandler(); $input = 'ccff33'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([204, 255, 51, 255], $result->toArray()); $handler = new InputHandler(); $input = 'cf3'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([204, 255, 51, 255], $result->toArray()); $handler = new InputHandler(); $input = '#123456'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([18, 52, 86, 255], $result->toArray()); $handler = new InputHandler(); $input = '#333'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 255], $result->toArray()); $handler = new InputHandler(); $input = '#3333'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 51], $result->toArray()); $handler = new InputHandler(); $input = '#33333333'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 51], $result->toArray()); } @@ -96,12 +96,12 @@ class GdInputHandlerTest extends TestCase { $handler = new InputHandler(); $result = $handler->handle('rgb(10, 20, 30)'); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([10, 20, 30, 255], $result->toArray()); $handler = new InputHandler(); $result = $handler->handle('rgba(10, 20, 30, 1.0)'); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([10, 20, 30, 255], $result->toArray()); } @@ -110,7 +110,7 @@ class GdInputHandlerTest extends TestCase $handler = new InputHandler(); $input = 'transparent'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([0, 0, 0, 0], $result->toArray()); } } diff --git a/tests/Drivers/Imagick/InputHandlerTest.php b/tests/Drivers/Imagick/InputHandlerTest.php index ed7a99ca..876a59e0 100644 --- a/tests/Drivers/Imagick/InputHandlerTest.php +++ b/tests/Drivers/Imagick/InputHandlerTest.php @@ -2,7 +2,7 @@ namespace Intervention\Image\Tests\Drivers\Imagick; -use Intervention\Image\Colors\Rgb\Color; +use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Drivers\Imagick\Image; use Intervention\Image\Drivers\Imagick\InputHandler; use Intervention\Image\Exceptions\DecoderException; @@ -58,37 +58,37 @@ class InputHandlerTest extends TestCase $handler = new InputHandler(); $input = 'ccff33'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([204, 255, 51, 255], $result->toArray()); $handler = new InputHandler(); $input = 'cf3'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([204, 255, 51, 255], $result->toArray()); $handler = new InputHandler(); $input = '#123456'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([18, 52, 86, 255], $result->toArray()); $handler = new InputHandler(); $input = '#333'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 255], $result->toArray()); $handler = new InputHandler(); $input = '#3333'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 51], $result->toArray()); $handler = new InputHandler(); $input = '#33333333'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 51], $result->toArray()); } @@ -96,12 +96,12 @@ class InputHandlerTest extends TestCase { $handler = new InputHandler(); $result = $handler->handle('rgb(10, 20, 30)'); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([10, 20, 30, 255], $result->toArray()); $handler = new InputHandler(); $result = $handler->handle('rgba(10, 20, 30, 1.0)'); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([10, 20, 30, 255], $result->toArray()); } @@ -110,7 +110,7 @@ class InputHandlerTest extends TestCase $handler = new InputHandler(); $input = 'transparent'; $result = $handler->handle($input); - $this->assertInstanceOf(Color::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([0, 0, 0, 0], $result->toArray()); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index f73c069c..8f76a724 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,8 @@ namespace Intervention\Image\Tests; -use Intervention\Image\Colors\Rgb\Color; -use Intervention\Image\Colors\Rgb\Colorspace; +use Intervention\Image\Colors\Rgb\Channels\Alpha; +use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Interfaces\ColorInterface; use Mockery\Adapter\Phpunit\MockeryTestCase; @@ -26,7 +26,8 @@ abstract class TestCase extends MockeryTestCase protected function assertTransparency(ColorInterface $color) { - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals(0, $color->convertTo(Colorspace::class)->alpha()->value()); + $this->assertInstanceOf(RgbColor::class, $color); + $channel = $color->channel(Alpha::class); + $this->assertEquals(0, $channel->value()); } }