Skip to content

Commit aeb7e21

Browse files
committed
Update ColorProcessorInterface
1 parent 8490d38 commit aeb7e21

34 files changed

Lines changed: 89 additions & 86 deletions

src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace Intervention\Image\Drivers\Gd\Analyzers;
66

7-
use GdImage;
87
use Intervention\Image\Analyzers\PixelColorAnalyzer as GenericPixelColorAnalyzer;
98
use Intervention\Image\Exceptions\AnalyzerException;
109
use Intervention\Image\Exceptions\InvalidArgumentException;
1110
use Intervention\Image\Exceptions\StateException;
1211
use Intervention\Image\Interfaces\ColorInterface;
13-
use Intervention\Image\Interfaces\ColorspaceInterface;
12+
use Intervention\Image\Interfaces\ColorProcessorInterface;
13+
use Intervention\Image\Interfaces\FrameInterface;
1414
use Intervention\Image\Interfaces\ImageInterface;
1515
use Intervention\Image\Interfaces\SpecializedInterface;
1616
use ValueError;
@@ -28,19 +28,14 @@ class PixelColorAnalyzer extends GenericPixelColorAnalyzer implements Specialize
2828
*/
2929
public function analyze(ImageInterface $image): mixed
3030
{
31-
return $this->colorAt(
32-
$image->colorspace(),
33-
$image->core()->frame($this->frame)->native()
34-
);
31+
$colorProcessor = $this->driver()->colorProcessor($image);
32+
33+
return $this->colorAt($colorProcessor, $image->core()->frame($this->frame));
3534
}
3635

37-
/**
38-
* @throws InvalidArgumentException
39-
* @throws AnalyzerException
40-
* @throws StateException
41-
*/
42-
protected function colorAt(ColorspaceInterface $colorspace, GdImage $gd): ColorInterface
36+
protected function colorAt(ColorProcessorInterface $processor, FrameInterface $frame): ColorInterface
4337
{
38+
$gd = $frame->native();
4439
$index = @imagecolorat($gd, $this->x, $this->y);
4540

4641
if (!is_int($index)) {
@@ -57,6 +52,6 @@ protected function colorAt(ColorspaceInterface $colorspace, GdImage $gd): ColorI
5752
);
5853
}
5954

60-
return $this->driver()->colorProcessor($colorspace)->nativeToColor($index);
55+
return $processor->nativeToColor($index);
6156
}
6257
}

src/Drivers/Gd/Analyzers/PixelColorsAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class PixelColorsAnalyzer extends PixelColorAnalyzer
1717
public function analyze(ImageInterface $image): mixed
1818
{
1919
$colors = new Collection();
20-
$colorspace = $image->colorspace();
20+
$colorProcessor = $this->driver()->colorProcessor($image);
2121

2222
foreach ($image as $frame) {
2323
$colors->push(
24-
parent::colorAt($colorspace, $frame->native())
24+
parent::colorAt($colorProcessor, $frame)
2525
);
2626
}
2727

src/Drivers/Gd/ColorProcessor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Intervention\Image\Colors\Rgb\Channels\Green;
1010
use Intervention\Image\Colors\Rgb\Channels\Red;
1111
use Intervention\Image\Colors\Rgb\Color;
12-
use Intervention\Image\Colors\Rgb\Colorspace;
12+
use Intervention\Image\Colors\Rgb\Colorspace as Rgb;
1313
use Intervention\Image\Exceptions\ColorDecoderException;
1414
use Intervention\Image\Interfaces\ColorInterface;
1515
use Intervention\Image\Interfaces\ColorProcessorInterface;
@@ -18,13 +18,13 @@
1818
class ColorProcessor implements ColorProcessorInterface
1919
{
2020
/**
21-
* Create new color processor object
21+
* {@inheritdoc}
2222
*
23-
* @return void
23+
* @see ColorProcessorInterface::colorspace()
2424
*/
25-
public function __construct(protected ColorspaceInterface $colorspace = new Colorspace())
25+
public function colorspace(): ColorspaceInterface
2626
{
27-
//
27+
return new Rgb();
2828
}
2929

3030
/**
@@ -35,7 +35,7 @@ public function __construct(protected ColorspaceInterface $colorspace = new Colo
3535
public function colorToNative(ColorInterface $color): int
3636
{
3737
// convert color to colorspace
38-
$color = $color->toColorspace($this->colorspace);
38+
$color = $color->toColorspace($this->colorspace());
3939

4040
// gd only supports rgb so the channels can be accessed directly
4141
$r = $color->channel(Red::class)->value();

src/Drivers/Gd/Driver.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Intervention\Image\FileExtension;
1414
use Intervention\Image\Image;
1515
use Intervention\Image\Interfaces\ColorProcessorInterface;
16-
use Intervention\Image\Interfaces\ColorspaceInterface;
1716
use Intervention\Image\Interfaces\CoreInterface;
1817
use Intervention\Image\Interfaces\FontProcessorInterface;
1918
use Intervention\Image\Interfaces\ImageInterface;
@@ -98,9 +97,9 @@ public function createCore(array $frames): CoreInterface
9897
*
9998
* @see DriverInterface::colorProcessor()
10099
*/
101-
public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface
100+
public function colorProcessor(ImageInterface $image): ColorProcessorInterface
102101
{
103-
return new ColorProcessor($colorspace);
102+
return new ColorProcessor();
104103
}
105104

106105
/**

src/Drivers/Gd/Modifiers/DrawBezierModifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function apply(ImageInterface $image): ImageInterface
4040
}
4141

4242
if ($this->drawable->hasBackgroundColor()) {
43-
$backgroundColor = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
43+
$backgroundColor = $this->driver()->colorProcessor($image)->colorToNative(
4444
$this->backgroundColor()
4545
);
4646

@@ -57,7 +57,7 @@ public function apply(ImageInterface $image): ImageInterface
5757
}
5858

5959
if ($this->drawable->hasBorder() && $this->drawable->borderSize() > 0) {
60-
$borderColor = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
60+
$borderColor = $this->driver()->colorProcessor($image)->colorToNative(
6161
$this->borderColor()
6262
);
6363

src/Drivers/Gd/Modifiers/DrawEllipseModifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function apply(ImageInterface $image): ImageInterface
3434
$this->drawable->position()->y(),
3535
$this->drawable->width() - 1,
3636
$this->drawable->height() - 1,
37-
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
37+
$this->driver()->colorProcessor($image)->colorToNative(
3838
$this->backgroundColor()
3939
)
4040
);
@@ -55,7 +55,7 @@ public function apply(ImageInterface $image): ImageInterface
5555
$this->drawable->height(),
5656
0,
5757
360,
58-
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
58+
$this->driver()->colorProcessor($image)->colorToNative(
5959
$this->borderColor()
6060
)
6161
);
@@ -68,7 +68,7 @@ public function apply(ImageInterface $image): ImageInterface
6868
$this->drawable()->position()->y(),
6969
$this->drawable->width(),
7070
$this->drawable->height(),
71-
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
71+
$this->driver()->colorProcessor($image)->colorToNative(
7272
$this->backgroundColor()
7373
)
7474
);

src/Drivers/Gd/Modifiers/DrawLineModifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function apply(ImageInterface $image): ImageInterface
2323
return $image;
2424
}
2525

26-
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
26+
$color = $this->driver()->colorProcessor($image)->colorToNative(
2727
$this->backgroundColor()
2828
);
2929

src/Drivers/Gd/Modifiers/DrawPixelModifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DrawPixelModifier extends GenericDrawPixelModifier implements SpecializedI
2222
*/
2323
public function apply(ImageInterface $image): ImageInterface
2424
{
25-
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
25+
$color = $this->driver()->colorProcessor($image)->colorToNative(
2626
$this->driver()->handleColorInput($this->color)
2727
);
2828

src/Drivers/Gd/Modifiers/DrawPolygonModifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function apply(ImageInterface $image): ImageInterface
2929
imagefilledpolygon(
3030
$frame->native(),
3131
$this->drawable->toArray(),
32-
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
32+
$this->driver()->colorProcessor($image)->colorToNative(
3333
$this->backgroundColor()
3434
)
3535
);
@@ -41,7 +41,7 @@ public function apply(ImageInterface $image): ImageInterface
4141
imagepolygon(
4242
$frame->native(),
4343
$this->drawable->toArray(),
44-
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
44+
$this->driver()->colorProcessor($image)->colorToNative(
4545
$this->borderColor()
4646
)
4747
);

src/Drivers/Gd/Modifiers/DrawRectangleModifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function apply(ImageInterface $image): ImageInterface
3535
$position->y(),
3636
$position->x() + $this->drawable->width(),
3737
$position->y() + $this->drawable->height(),
38-
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
38+
$this->driver()->colorProcessor($image)->colorToNative(
3939
$this->backgroundColor()
4040
)
4141
);
@@ -51,7 +51,7 @@ public function apply(ImageInterface $image): ImageInterface
5151
$position->y(),
5252
$position->x() + $this->drawable->width(),
5353
$position->y() + $this->drawable->height(),
54-
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
54+
$this->driver()->colorProcessor($image)->colorToNative(
5555
$this->borderColor()
5656
)
5757
);

0 commit comments

Comments
 (0)