diff --git a/src/Colors/Cmyk/Color.php b/src/Colors/Cmyk/Color.php index 74ee0540..bf6cb401 100644 --- a/src/Colors/Cmyk/Color.php +++ b/src/Colors/Cmyk/Color.php @@ -9,8 +9,6 @@ use Intervention\Image\Colors\Cmyk\Channels\Key; use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace; use Intervention\Image\Colors\Rgb\Color as RgbColor; use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace; -use Intervention\Image\Colors\Rgba\Colorspace as RgbaColorspace; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Colors\Traits\CanHandleChannels; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -81,11 +79,6 @@ class Color implements ColorInterface return $this->convertTo(RgbColorspace::class); } - public function toRgba(): RgbaColor - { - return $this->convertTo(RgbaColorspace::class); - } - public function toCmyk(): self { return $this->convertTo(CmykColorspace::class); diff --git a/src/Colors/Cmyk/Colorspace.php b/src/Colors/Cmyk/Colorspace.php index 69c6c82a..76ce8ea3 100644 --- a/src/Colors/Cmyk/Colorspace.php +++ b/src/Colors/Cmyk/Colorspace.php @@ -3,7 +3,6 @@ namespace Intervention\Image\Colors\Cmyk; use Intervention\Image\Colors\Rgb\Color as RgbColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -18,7 +17,7 @@ class Colorspace implements ColorspaceInterface public function convertColor(ColorInterface $color): ColorInterface { return match (get_class($color)) { - RgbColor::class, RgbaColor::class => $this->convertRgbColor($color), + RgbColor::class => $this->convertRgbColor($color), default => $color, }; } diff --git a/src/Colors/Parser.php b/src/Colors/Parser.php index edd2b2b4..dcf91c59 100644 --- a/src/Colors/Parser.php +++ b/src/Colors/Parser.php @@ -9,7 +9,6 @@ class Parser { protected static $parsers = [ Rgb\Parser::class, - Rgba\Parser::class, Cmyk\Parser::class, ]; diff --git a/src/Colors/Rgba/Channels/Alpha.php b/src/Colors/Rgb/Channels/Alpha.php similarity index 81% rename from src/Colors/Rgba/Channels/Alpha.php rename to src/Colors/Rgb/Channels/Alpha.php index e69a437e..7172791f 100644 --- a/src/Colors/Rgba/Channels/Alpha.php +++ b/src/Colors/Rgb/Channels/Alpha.php @@ -1,6 +1,6 @@ channels = [ new Red($r), new Green($g), new Blue($b), + new Alpha($a), ]; } @@ -44,6 +44,11 @@ class Color implements ColorInterface return $this->channel(Blue::class); } + public function alpha(): Alpha + { + return $this->channel(Alpha::class); + } + public function toArray(): array { return array_map(function (ColorChannelInterface $channel) { @@ -53,12 +58,23 @@ class Color implements ColorInterface public function toHex(string $prefix = ''): string { + if ($this->isFullyOpaque()) { + return sprintf( + '%s%02x%02x%02x', + $prefix, + $this->red()->value(), + $this->green()->value(), + $this->blue()->value() + ); + } + return sprintf( - '%s%02x%02x%02x', + '%s%02x%02x%02x%02x', $prefix, $this->red()->value(), $this->green()->value(), - $this->blue()->value() + $this->blue()->value(), + $this->alpha()->value() ); } @@ -82,18 +98,28 @@ class Color implements ColorInterface return $this->convertTo(CmykColorspace::class); } - public function toRgba(): RgbaColor + public function isFullyOpaque(): bool { - return $this->convertTo(RgbaColorspace::class); + return $this->alpha()->value() === 255; } public function toString(): string { + if ($this->isFullyOpaque()) { + return sprintf( + 'rgb(%d, %d, %d)', + $this->red()->value(), + $this->green()->value(), + $this->blue()->value() + ); + } + return sprintf( - 'rgb(%d, %d, %d)', + 'rgba(%d, %d, %d, %.1F)', $this->red()->value(), $this->green()->value(), - $this->blue()->value() + $this->blue()->value(), + $this->alpha()->normalize(), ); } diff --git a/src/Colors/Rgb/Colorspace.php b/src/Colors/Rgb/Colorspace.php index 489df51d..4c0bcb0f 100644 --- a/src/Colors/Rgb/Colorspace.php +++ b/src/Colors/Rgb/Colorspace.php @@ -3,7 +3,6 @@ namespace Intervention\Image\Colors\Rgb; use Intervention\Image\Colors\Cmyk\Color as CmykColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -13,7 +12,6 @@ class Colorspace implements ColorspaceInterface { return match (get_class($color)) { CmykColor::class => $this->convertCmykColor($color), - RgbaColor::class => $this->convertRgbaColor($color), default => $color, }; } @@ -26,13 +24,4 @@ class Colorspace implements ColorspaceInterface (int) (255 * (1 - $color->yellow()->normalize()) * (1 - $color->key()->normalize())), ); } - - protected function convertRgbaColor(RgbaColor $color): Color - { - return new Color( - $color->red()->value(), - $color->green()->value(), - $color->blue()->value() - ); - } } diff --git a/src/Colors/Rgb/Parser.php b/src/Colors/Rgb/Parser.php index 82aef1e6..746a40d6 100644 --- a/src/Colors/Rgb/Parser.php +++ b/src/Colors/Rgb/Parser.php @@ -35,6 +35,7 @@ class Parser public static function fromHex(string $input): Color { + // Hexadecimal colors $pattern = '/^#?(?P[0-9a-f]{3}|[0-9a-f]{6})$/i'; $result = preg_match($pattern, $input, $matches); @@ -48,10 +49,35 @@ class Parser default => throw new ColorException('Unable to parse color'), }; + try { + return new Color( + strlen($matches[0]) == '1' ? hexdec($matches[0] . $matches[0]) : hexdec($matches[0]), + strlen($matches[1]) == '1' ? hexdec($matches[1] . $matches[1]) : hexdec($matches[1]), + strlen($matches[2]) == '1' ? hexdec($matches[2] . $matches[2]) : hexdec($matches[2]) + ); + } catch (ColorException $e) { + # move on + } + + // Hexadecimal colors with transparency + $pattern = '/^#?(?P[0-9a-f]{4}|[0-9a-f]{8})$/i'; + $result = preg_match($pattern, $input, $matches); + + if ($result !== 1) { + throw new ColorException('Unable to parse color'); + } + + $matches = match (strlen($matches['hex'])) { + 4 => str_split($matches['hex']), + 8 => str_split($matches['hex'], 2), + default => throw new ColorException('Unable to parse color'), + }; + return new Color( strlen($matches[0]) == '1' ? hexdec($matches[0] . $matches[0]) : hexdec($matches[0]), strlen($matches[1]) == '1' ? hexdec($matches[1] . $matches[1]) : hexdec($matches[1]), strlen($matches[2]) == '1' ? hexdec($matches[2] . $matches[2]) : hexdec($matches[2]), + strlen($matches[3]) == '1' ? hexdec($matches[3] . $matches[3]) : hexdec($matches[3]), ); } @@ -79,6 +105,31 @@ class Parser ); } + // rgba(255, 255, 255, 1.0) + $pattern = '/^s?rgba\((?P[0-9]{1,3}), *(?P[0-9]{1,3}), *(?P[0-9]{1,3}), *(?P((1|0))?(\.[0-9]+)?)\)$/'; + $result = preg_match($pattern, $input, $matches); + + if ($result === 1) { + return new Color( + $matches['r'], + $matches['g'], + $matches['b'], + intval(round(floatval($matches['a']) * 255)) + ); + } + + // rgba(100%, 100%, 100%, 100%) + $pattern = '/s?rgba\((?P[0-9\.]+)%, ?(?P[0-9\.]+)%, ?(?P[0-9\.]+)%, ?(?P[0-9\.]+)%\)/'; + $result = preg_match($pattern, $input, $matches); + if ($result === 1) { + return new Color( + intval(round(floatval($matches['r']) / 100 * 255)), + intval(round(floatval($matches['g']) / 100 * 255)), + intval(round(floatval($matches['b']) / 100 * 255)), + intval(round(floatval($matches['a']) / 100 * 255)) + ); + } + throw new ColorException('Unable to parse color'); } diff --git a/src/Colors/Rgba/Channels/Blue.php b/src/Colors/Rgba/Channels/Blue.php deleted file mode 100644 index 54b9d5bc..00000000 --- a/src/Colors/Rgba/Channels/Blue.php +++ /dev/null @@ -1,10 +0,0 @@ -channels = [ - new Red($r), - new Green($g), - new Blue($b), - new Alpha($a), - ]; - } - - public function red(): Red - { - return $this->channel(Red::class); - } - - public function green(): Green - { - return $this->channel(Green::class); - } - - public function blue(): Blue - { - return $this->channel(Blue::class); - } - - public function alpha(): Alpha - { - return $this->channel(Alpha::class); - } - - public function isFullyOpaque(): bool - { - return $this->alpha()->value() === 255; - } - - public function toHex(string $prefix = ''): string - { - if ($this->isFullyOpaque()) { - return parent::toHex($prefix); - } - - return sprintf( - '%s%02x%02x%02x%02x', - $prefix, - $this->red()->value(), - $this->green()->value(), - $this->blue()->value(), - $this->alpha()->value() - ); - } - - public function toRgb(): RgbColor - { - return $this->convertTo(RgbColorspace::class); - } - - public function toRgba(): self - { - return $this; - } - - public function toCmyk(): CmykColor - { - return $this->convertTo(CmykColorspace::class); - } - - public function toString(): string - { - return sprintf( - 'rgba(%d, %d, %d, %.1F)', - $this->red()->value(), - $this->green()->value(), - $this->blue()->value(), - $this->alpha()->normalize(), - ); - } - - public function __toString(): string - { - return $this->toString(); - } -} diff --git a/src/Colors/Rgba/Colorspace.php b/src/Colors/Rgba/Colorspace.php deleted file mode 100644 index 28b53f83..00000000 --- a/src/Colors/Rgba/Colorspace.php +++ /dev/null @@ -1,55 +0,0 @@ - $this->convertCmykColor($color), - RgbColor::class => $this->convertRgbColor($color), - default => $color, - }; - } - - /** - * Convert given color to the RGBA colorspace - * - * @param RgbColor $color - * @return Color - */ - protected function convertRgbColor(RgbColor $color): Color - { - return new Color( - $color->red()->value(), - $color->green()->value(), - $color->blue()->value(), - 255 - ); - } - - /** - * Convert given color to the RGBA colorspace - * - * @param CmykColor $color - * @return 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())), - 255 - ); - } -} diff --git a/src/Colors/Rgba/Parser.php b/src/Colors/Rgba/Parser.php deleted file mode 100644 index efaa9f70..00000000 --- a/src/Colors/Rgba/Parser.php +++ /dev/null @@ -1,68 +0,0 @@ -toRgba(); - } catch (ColorException $e) { - // move on - } - - $pattern = '/^#?(?P[0-9a-f]{4}|[0-9a-f]{8})$/i'; - $result = preg_match($pattern, $input, $matches); - - if ($result !== 1) { - throw new ColorException('Unable to parse color'); - } - - $matches = match (strlen($matches['hex'])) { - 4 => str_split($matches['hex']), - 8 => str_split($matches['hex'], 2), - default => throw new ColorException('Unable to parse color'), - }; - - return new Color( - strlen($matches[0]) == '1' ? hexdec($matches[0] . $matches[0]) : hexdec($matches[0]), - strlen($matches[1]) == '1' ? hexdec($matches[1] . $matches[1]) : hexdec($matches[1]), - strlen($matches[2]) == '1' ? hexdec($matches[2] . $matches[2]) : hexdec($matches[2]), - strlen($matches[3]) == '1' ? hexdec($matches[3] . $matches[3]) : hexdec($matches[3]), - ); - } - - public static function fromString(string $input): Color - { - // rgba(255, 255, 255, 1.0) - $pattern = '/^s?rgba\((?P[0-9]{1,3}), *(?P[0-9]{1,3}), *(?P[0-9]{1,3}), *(?P((1|0))?(\.[0-9]+)?)\)$/'; - $result = preg_match($pattern, $input, $matches); - - if ($result === 1) { - return new Color( - $matches['r'], - $matches['g'], - $matches['b'], - intval(round(floatval($matches['a']) * 255)) - ); - } - - // rgba(100%, 100%, 100%, 100%) - $pattern = '/s?rgba\((?P[0-9\.]+)%, ?(?P[0-9\.]+)%, ?(?P[0-9\.]+)%, ?(?P[0-9\.]+)%\)/'; - $result = preg_match($pattern, $input, $matches); - if ($result === 1) { - return new Color( - intval(round(floatval($matches['r']) / 100 * 255)), - intval(round(floatval($matches['g']) / 100 * 255)), - intval(round(floatval($matches['b']) / 100 * 255)), - intval(round(floatval($matches['a']) / 100 * 255)) - ); - } - - throw new ColorException('Unable to parse color'); - } -} diff --git a/src/Drivers/Gd/ColorTransformer.php b/src/Drivers/Gd/ColorTransformer.php index aac312e7..62d9c8bd 100644 --- a/src/Drivers/Gd/ColorTransformer.php +++ b/src/Drivers/Gd/ColorTransformer.php @@ -3,12 +3,12 @@ namespace Intervention\Image\Drivers\Gd; use Intervention\Image\Interfaces\ColorInterface; -use Intervention\Image\Colors\Rgba\Color; +use Intervention\Image\Colors\Rgb\Color; class ColorTransformer { /** - * Transforms GD Library integer color value to RGBA color object + * Transforms GD Library integer color value to RGB color object * * @param int $value * @return Color @@ -35,7 +35,7 @@ class ColorTransformer */ public static function colorToInteger(ColorInterface $color): int { - $color = $color->toRgba(); + $color = $color->toRgb(); $r = $color->red()->value(); $g = $color->green()->value(); diff --git a/src/Interfaces/ColorInterface.php b/src/Interfaces/ColorInterface.php index 46a4dab8..7cf18317 100644 --- a/src/Interfaces/ColorInterface.php +++ b/src/Interfaces/ColorInterface.php @@ -4,12 +4,10 @@ namespace Intervention\Image\Interfaces; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Rgb\Color as RgbColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; interface ColorInterface { public function toRgb(): RgbColor; - public function toRgba(): RgbaColor; public function toCmyk(): CmykColor; public function toArray(): array; public function toString(): string; diff --git a/tests/Colors/Cmyk/ColorTest.php b/tests/Colors/Cmyk/ColorTest.php index 2052480f..66e87283 100644 --- a/tests/Colors/Cmyk/ColorTest.php +++ b/tests/Colors/Cmyk/ColorTest.php @@ -3,7 +3,6 @@ namespace Intervention\Image\Tests\Colors\Cmyk; use Intervention\Image\Colors\Rgb\Color as RgbColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Colors\Cmyk\Channels\Cyan; use Intervention\Image\Colors\Cmyk\Channels\Key; use Intervention\Image\Colors\Cmyk\Channels\Magenta; @@ -83,12 +82,4 @@ class ColorTest extends TestCase $this->assertInstanceOf(RgbColor::class, $converted); $this->assertEquals([255, 204, 204], $converted->toArray()); } - - public function testToRgba(): void - { - $color = new Color(0, 20, 20, 0); - $converted = $color->toRgba(); - $this->assertInstanceOf(RgbaColor::class, $converted); - $this->assertEquals([255, 204, 204, 255], $converted->toArray()); - } } diff --git a/tests/Colors/ParserTest.php b/tests/Colors/ParserTest.php index a783f62a..4e158140 100644 --- a/tests/Colors/ParserTest.php +++ b/tests/Colors/ParserTest.php @@ -4,7 +4,6 @@ namespace Intervention\Image\Tests\Colors; use Intervention\Image\Colors\Cmyk\Color as CmykColor; use Intervention\Image\Colors\Rgb\Color as RgbColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Colors\Parser; use Intervention\Image\Tests\TestCase; @@ -25,7 +24,7 @@ class ParserTest extends TestCase $this->assertEquals([204, 204, 204], $color->toArray()); $color = Parser::parse('rgba(204, 204, 204, 1)'); - $this->assertInstanceOf(RgbaColor::class, $color); + $this->assertInstanceOf(RgbColor::class, $color); $this->assertEquals([204, 204, 204, 255], $color->toArray()); $color = Parser::parse('cccc'); diff --git a/tests/Colors/Rgb/ColorTest.php b/tests/Colors/Rgb/ColorTest.php index 5c542fa7..8121a47f 100644 --- a/tests/Colors/Rgb/ColorTest.php +++ b/tests/Colors/Rgb/ColorTest.php @@ -3,7 +3,6 @@ namespace Intervention\Image\Tests\Colors\Rgb; use Intervention\Image\Colors\Cmyk\Color as CmykColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Blue; @@ -111,12 +110,4 @@ class ColorTest extends TestCase $color = new Color(181, 55, 23); $this->assertInstanceOf(Color::class, $color->toRgb()); } - - public function testToRgba(): void - { - $color = new Color(181, 55, 23); - $converted = $color->toRgba(); - $this->assertInstanceOf(RgbaColor::class, $converted); - $this->assertEquals([181, 55, 23, 255], $converted->toArray()); - } } diff --git a/tests/Colors/Rgb/ParserTest.php b/tests/Colors/Rgb/ParserTest.php index b6ccce7d..d98b8601 100644 --- a/tests/Colors/Rgb/ParserTest.php +++ b/tests/Colors/Rgb/ParserTest.php @@ -69,9 +69,6 @@ class ParserTest extends TestCase $this->expectException(ColorException::class); (new Parser())->fromString('rgb(120)'); - - $this->expectException(ColorException::class); - (new Parser())->fromString('rgba(204,204,204,1)'); } public function testFromName(): void diff --git a/tests/Colors/Rgba/ChannelTest.php b/tests/Colors/Rgba/ChannelTest.php deleted file mode 100644 index 3edcca17..00000000 --- a/tests/Colors/Rgba/ChannelTest.php +++ /dev/null @@ -1,67 +0,0 @@ -assertInstanceOf(Channel::class, $channel); - } - - public function testValue(): void - { - $channel = new Channel(10); - $this->assertEquals(10, $channel->value()); - } - - public function testNormalize(): void - { - $channel = new Channel(255); - $this->assertEquals(1, $channel->normalize()); - $channel = new Channel(0); - $this->assertEquals(0, $channel->normalize()); - $channel = new Channel(51); - $this->assertEquals(.2, $channel->normalize()); - } - - public function testValidate(): void - { - $this->expectException(ColorException::class); - new Channel(256); - - $this->expectException(ColorException::class); - new Channel(-1); - } - - public function testToString(): void - { - $channel = new Channel(255); - $this->assertEquals("255", $channel->toString()); - - $channel = new Alpha(0); - $this->assertEquals("0", $channel->toString()); - - $channel = new Alpha(51); - $this->assertEquals("0.2", $channel->toString()); - - $channel = new Alpha(255); - $this->assertEquals("1", $channel->toString()); - - $channel = new Alpha(170); - $this->assertEquals("0.666667", $channel->toString()); - } -} diff --git a/tests/Colors/Rgba/ColorTest.php b/tests/Colors/Rgba/ColorTest.php deleted file mode 100644 index cf9b9e61..00000000 --- a/tests/Colors/Rgba/ColorTest.php +++ /dev/null @@ -1,119 +0,0 @@ -assertInstanceOf(Color::class, $color); - } - - public function testChannels(): void - { - $color = new Color(10, 20, 30, 255); - $this->assertIsArray($color->channels()); - $this->assertCount(4, $color->channels()); - } - - public function testChannel(): void - { - $color = new Color(10, 20, 30, 255); - $channel = $color->channel(Red::class); - $this->assertInstanceOf(Red::class, $channel); - $this->assertEquals(10, $channel->value()); - $channel = $color->channel(Alpha::class); - $this->assertInstanceOf(Alpha::class, $channel); - $this->assertEquals(255, $channel->value()); - } - - public function testRedGreenBlueAlpha(): void - { - $color = new Color(10, 20, 30, 255); - $this->assertInstanceOf(Red::class, $color->red()); - $this->assertInstanceOf(Green::class, $color->green()); - $this->assertInstanceOf(Blue::class, $color->blue()); - $this->assertInstanceOf(Alpha::class, $color->alpha()); - $this->assertEquals(10, $color->red()->value()); - $this->assertEquals(20, $color->green()->value()); - $this->assertEquals(30, $color->blue()->value()); - $this->assertEquals(255, $color->alpha()->value()); - } - - public function testToArray(): void - { - $color = new Color(10, 20, 30, 255); - $this->assertEquals([10, 20, 30, 255], $color->toArray()); - } - - public function testToHex(): void - { - $color = new Color(181, 55, 23, 0); - $this->assertEquals('b5371700', $color->toHex()); - $this->assertEquals('#b5371700', $color->toHex('#')); - - $color = new Color(181, 55, 23, 255); - $this->assertEquals('b53717', $color->toHex()); - - $color = new Color(181, 55, 23, 204); - $this->assertEquals('b53717cc', $color->toHex()); - } - - public function testNormalize(): void - { - $color = new Color(255, 0, 51, 255); - $this->assertEquals([1.0, 0.0, 0.2, 1.0], $color->normalize()); - $color = new Color(255, 0, 51, 51); - $this->assertEquals([1.0, 0.0, 0.2, 0.2], $color->normalize()); - } - - public function testToString(): void - { - $color = new Color(255, 255, 255, 255); - $this->assertEquals('rgba(255, 255, 255, 1.0)', (string) $color); - - $color = new Color(10, 20, 30, 85); - $this->assertEquals('rgba(10, 20, 30, 0.3)', (string) $color); - } - - public function testToRgba(): void - { - $color = new Color(181, 55, 23, 120); - $converted = $color->toRgba(); - $this->assertInstanceOf(Color::class, $converted); - } - - public function testToRgb(): void - { - $color = new Color(181, 55, 23, 120); - $converted = $color->toRgb(); - $this->assertInstanceOf(RgbColor::class, $converted); - $this->assertEquals([181, 55, 23], $converted->toArray()); - } - - public function testToCmyk(): void - { - $color = new Color(0, 0, 0, 255); - $converted = $color->toCmyk(); - $this->assertInstanceOf(CmykColor::class, $converted); - $this->assertEquals([0, 0, 0, 100], $converted->toArray()); - - $color = new Color(0, 0, 0, 0); - $converted = $color->toCmyk(); - $this->assertInstanceOf(CmykColor::class, $converted); - $this->assertEquals([0, 0, 0, 100], $converted->toArray()); - } -} diff --git a/tests/Colors/Rgba/ColorspaceTest.php b/tests/Colors/Rgba/ColorspaceTest.php deleted file mode 100644 index 2ff88b0f..00000000 --- a/tests/Colors/Rgba/ColorspaceTest.php +++ /dev/null @@ -1,26 +0,0 @@ -assertInstanceOf( - RgbaColor::class, - $colorspace->convertColor( - new CmykColor(0, 0, 0, 0) - ) - ); - } -} diff --git a/tests/Colors/Rgba/ParserTest.php b/tests/Colors/Rgba/ParserTest.php deleted file mode 100644 index 89441646..00000000 --- a/tests/Colors/Rgba/ParserTest.php +++ /dev/null @@ -1,91 +0,0 @@ -assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Parser::parse('rgba(204, 204, 204, 1)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Parser::parse('salmon'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals('fa8072', $color->toHex()); - } - - public function testFromHex(): void - { - $color = Parser::fromHex('ccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Parser::fromHex('cccccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Parser::fromHex('#cccccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Parser::fromHex('#cccccccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 204], $color->toArray()); - - $color = Parser::fromHex('#cccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 204], $color->toArray()); - - $color = Parser::fromHex('cccccccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 204], $color->toArray()); - - $color = Parser::fromHex('cccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 204], $color->toArray()); - } - - public function testFromString(): void - { - $color = Parser::fromString('rgba(204, 204, 204, 1)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Parser::fromString('rgba(204,204,204,1.0)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Parser::fromString('rgba(204,204,204,0.2)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 51], $color->toArray()); - - $color = Parser::fromString('rgba(204,204, 204, .2)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 51], $color->toArray()); - - $color = Parser::fromString('rgba(100%,20%,25%,100%)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([255, 51, 64, 255], $color->toArray()); - - $color = Parser::fromString('rgba(100%,74.8064%,25.2497%,100%)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([255, 191, 64, 255], $color->toArray()); - - $this->expectException(ColorException::class); - $color = Parser::fromString('rgba(204, 204, 204, 1.2)'); - } -} diff --git a/tests/Drivers/Gd/ColorTransformerTest.php b/tests/Drivers/Gd/ColorTransformerTest.php index 24a3fa7c..04260235 100644 --- a/tests/Drivers/Gd/ColorTransformerTest.php +++ b/tests/Drivers/Gd/ColorTransformerTest.php @@ -2,7 +2,7 @@ namespace Intervention\Image\Tests\Drivers\Gd; -use Intervention\Image\Colors\Rgba\Color; +use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Drivers\Gd\ColorTransformer; use Intervention\Image\Tests\TestCase; diff --git a/tests/Drivers/Gd/Decoders/RgbStringColorDecoderTest.php b/tests/Drivers/Gd/Decoders/RgbStringColorDecoderTest.php index fa73370c..fb19fb98 100644 --- a/tests/Drivers/Gd/Decoders/RgbStringColorDecoderTest.php +++ b/tests/Drivers/Gd/Decoders/RgbStringColorDecoderTest.php @@ -3,7 +3,6 @@ namespace Intervention\Image\Tests\Drivers\Gd\Decoders; use Intervention\Image\Colors\Rgb\Color as RgbColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Drivers\Gd\Decoders\RgbStringColorDecoder; use Intervention\Image\Tests\TestCase; @@ -25,7 +24,7 @@ class RgbStringColorDecoderTest extends TestCase { $decoder = new RgbStringColorDecoder(); $color = $decoder->decode('rgba(181, 55, 23, 0.5)'); - $this->assertInstanceOf(RgbaColor::class, $color); + $this->assertInstanceOf(RgbColor::class, $color); $this->assertEquals([181, 55, 23, 51], $color->toArray()); } } diff --git a/tests/Drivers/Gd/InputHandlerTest.php b/tests/Drivers/Gd/InputHandlerTest.php index 8157f01a..3cdaaee2 100644 --- a/tests/Drivers/Gd/InputHandlerTest.php +++ b/tests/Drivers/Gd/InputHandlerTest.php @@ -3,7 +3,6 @@ namespace Intervention\Image\Tests\Drivers\Gd; use Intervention\Image\Colors\Rgb\Color as RgbColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Drivers\Gd\Image; use Intervention\Image\Drivers\Gd\InputHandler; use Intervention\Image\Exceptions\DecoderException; @@ -83,13 +82,13 @@ class GdInputHandlerTest extends TestCase $handler = new InputHandler(); $input = '#3333'; $result = $handler->handle($input); - $this->assertInstanceOf(RgbaColor::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(RgbaColor::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 51], $result->toArray()); } @@ -102,7 +101,7 @@ class GdInputHandlerTest extends TestCase $handler = new InputHandler(); $result = $handler->handle('rgba(10, 20, 30, 1.0)'); - $this->assertInstanceOf(RgbaColor::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([10, 20, 30, 255], $result->toArray()); } diff --git a/tests/Drivers/Imagick/ColorTransformerTest.php b/tests/Drivers/Imagick/ColorTransformerTest.php index fa71db90..49f16ad1 100644 --- a/tests/Drivers/Imagick/ColorTransformerTest.php +++ b/tests/Drivers/Imagick/ColorTransformerTest.php @@ -3,7 +3,7 @@ namespace Intervention\Image\Tests\Drivers\Imagick; use ImagickPixel; -use Intervention\Image\Colors\Rgba\Color; +use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Drivers\Imagick\ColorTransformer; use Intervention\Image\Tests\TestCase; diff --git a/tests/Drivers/Imagick/InputHandlerTest.php b/tests/Drivers/Imagick/InputHandlerTest.php index f125f686..e7ce923e 100644 --- a/tests/Drivers/Imagick/InputHandlerTest.php +++ b/tests/Drivers/Imagick/InputHandlerTest.php @@ -3,7 +3,6 @@ namespace Intervention\Image\Tests\Drivers\Imagick; use Intervention\Image\Colors\Rgb\Color as RgbColor; -use Intervention\Image\Colors\Rgba\Color as RgbaColor; use Intervention\Image\Drivers\Imagick\Image; use Intervention\Image\Drivers\Imagick\InputHandler; use Intervention\Image\Exceptions\DecoderException; @@ -83,13 +82,13 @@ class InputHandlerTest extends TestCase $handler = new InputHandler(); $input = '#3333'; $result = $handler->handle($input); - $this->assertInstanceOf(RgbaColor::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(RgbaColor::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([51, 51, 51, 51], $result->toArray()); } @@ -102,7 +101,7 @@ class InputHandlerTest extends TestCase $handler = new InputHandler(); $result = $handler->handle('rgba(10, 20, 30, 1.0)'); - $this->assertInstanceOf(RgbaColor::class, $result); + $this->assertInstanceOf(RgbColor::class, $result); $this->assertEquals([10, 20, 30, 255], $result->toArray()); } }