1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-20 04:31:24 +02:00

Remove remaining toRgb() calls

This commit is contained in:
Oliver Vogel
2023-10-21 09:25:36 +02:00
parent e3c8ca2edf
commit b5cbff3a89
7 changed files with 16 additions and 41 deletions

View File

@@ -76,11 +76,6 @@ class Color implements ColorInterface
); );
} }
public function toRgb(): self
{
return $this;
}
public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface
{ {
$colorspace = match (true) { $colorspace = match (true) {

View File

@@ -3,6 +3,7 @@
namespace Intervention\Image\Drivers\Gd\Traits; namespace Intervention\Image\Drivers\Gd\Traits;
use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
trait CanHandleColors trait CanHandleColors
@@ -33,9 +34,9 @@ trait CanHandleColors
* @param ColorInterface $color * @param ColorInterface $color
* @return int * @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(); $r = $color->red()->value();
$g = $color->green()->value(); $g = $color->green()->value();

View File

@@ -25,6 +25,7 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
$imagick = new Imagick(); $imagick = new Imagick();
$imagick->readImageBlob($input); $imagick->readImageBlob($input);
$imagick = $imagick->coalesceImages(); $imagick = $imagick->coalesceImages();
// $imagick->transformImageColorspace(Imagick::COLORSPACE_RGB);
$image = new Image($imagick); $image = new Image($imagick);
$image->setLoops($imagick->getImageIterations()); $image->setLoops($imagick->getImageIterations());

View File

@@ -2,16 +2,14 @@
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
use Intervention\Image\Colors\Rgb\Color;
interface ColorInterface 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 toString(): string;
public function toArray(): array;
public function toHex(): string;
public function channels(): array; public function channels(): array;
public function channel(string $classname): ColorChannelInterface;
public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface; public function convertTo(string|ColorspaceInterface $colorspace): ColorInterface;
public function isGreyscale(): bool; public function isGreyscale(): bool;
} }

View File

@@ -73,10 +73,4 @@ class ColorTest extends TestCase
$color = new Color(181, 55, 23); $color = new Color(181, 55, 23);
$this->assertEquals('rgb(181, 55, 23)', (string) $color); $this->assertEquals('rgb(181, 55, 23)', (string) $color);
} }
public function testToRgb(): void
{
$color = new Color(181, 55, 23);
$this->assertInstanceOf(Color::class, $color->toRgb());
}
} }

View File

@@ -96,21 +96,15 @@ class ImageTest extends TestCase
{ {
$color = $this->image->pickColor(0, 0); $color = $this->image->pickColor(0, 0);
$this->assertInstanceOf(Color::class, $color); $this->assertInstanceOf(Color::class, $color);
$this->assertEquals(255, $color->toRgb()->red()->value()); $this->assertEquals([255, 0, 0, 255], $color->toArray());
$this->assertEquals(0, $color->toRgb()->green()->value());
$this->assertEquals(0, $color->toRgb()->blue()->value());
$color = $this->image->pickColor(0, 0, 1); $color = $this->image->pickColor(0, 0, 1);
$this->assertInstanceOf(Color::class, $color); $this->assertInstanceOf(Color::class, $color);
$this->assertEquals(0, $color->toRgb()->red()->value()); $this->assertEquals([0, 255, 0, 255], $color->toArray());
$this->assertEquals(255, $color->toRgb()->green()->value());
$this->assertEquals(0, $color->toRgb()->blue()->value());
$color = $this->image->pickColor(0, 0, 2); $color = $this->image->pickColor(0, 0, 2);
$this->assertInstanceOf(Color::class, $color); $this->assertInstanceOf(Color::class, $color);
$this->assertEquals(0, $color->toRgb()->red()->value()); $this->assertEquals([0, 0, 255, 255], $color->toArray());
$this->assertEquals(0, $color->toRgb()->green()->value());
$this->assertEquals(255, $color->toRgb()->blue()->value());
$color = $this->image->pickColor(0, 0, 3); $color = $this->image->pickColor(0, 0, 3);
$this->assertNull($color); $this->assertNull($color);
@@ -121,17 +115,8 @@ class ImageTest extends TestCase
$colors = $this->image->pickColors(0, 0); $colors = $this->image->pickColors(0, 0);
$this->assertInstanceOf(Collection::class, $colors); $this->assertInstanceOf(Collection::class, $colors);
$this->assertCount(3, $colors); $this->assertCount(3, $colors);
$this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray());
$this->assertEquals(255, $colors->get(0)->toRgb()->red()->value()); $this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray());
$this->assertEquals(0, $colors->get(0)->toRgb()->green()->value()); $this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray());
$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());
} }
} }

View File

@@ -3,6 +3,7 @@
namespace Intervention\Image\Tests; namespace Intervention\Image\Tests;
use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Mockery\Adapter\Phpunit\MockeryTestCase; use Mockery\Adapter\Phpunit\MockeryTestCase;
@@ -26,6 +27,6 @@ abstract class TestCase extends MockeryTestCase
protected function assertTransparency(ColorInterface $color) protected function assertTransparency(ColorInterface $color)
{ {
$this->assertInstanceOf(Color::class, $color); $this->assertInstanceOf(Color::class, $color);
$this->assertEquals(0, $color->toRgb()->alpha()->value()); $this->assertEquals(0, $color->convertTo(Colorspace::class)->alpha()->value());
} }
} }