From c14d38ee79f693b1075a434d8af0ad91182c5e83 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Tue, 7 Jan 2025 19:43:51 +0100 Subject: [PATCH] Refactor color channel extraction --- src/Modifiers/ContainModifier.php | 11 +---------- src/Modifiers/PadModifier.php | 11 +---------- src/Modifiers/RotateModifier.php | 15 ++------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/Modifiers/ContainModifier.php b/src/Modifiers/ContainModifier.php index d161163..1b46db2 100644 --- a/src/Modifiers/ContainModifier.php +++ b/src/Modifiers/ContainModifier.php @@ -4,10 +4,6 @@ namespace Intervention\Image\Drivers\Vips\Modifiers; -use Intervention\Image\Colors\Rgb\Channels\Alpha; -use Intervention\Image\Colors\Rgb\Channels\Blue; -use Intervention\Image\Colors\Rgb\Channels\Green; -use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Drivers\Vips\Core; use Intervention\Image\Drivers\Vips\Traits\PositionToGravity; use Intervention\Image\Exceptions\ColorException; @@ -73,12 +69,7 @@ private function contain(FrameInterface $frame, SizeInterface $resize, ColorInte $resize->height(), [ 'extend' => Extend::BACKGROUND, - 'background' => [ - $bgColor->channel(Red::class)->value(), - $bgColor->channel(Green::class)->value(), - $bgColor->channel(Blue::class)->value(), - $bgColor->channel(Alpha::class)->value(), - ], + 'background' => $bgColor->toArray(), ] ) ); diff --git a/src/Modifiers/PadModifier.php b/src/Modifiers/PadModifier.php index 57cebc5..4a1e363 100644 --- a/src/Modifiers/PadModifier.php +++ b/src/Modifiers/PadModifier.php @@ -4,10 +4,6 @@ namespace Intervention\Image\Drivers\Vips\Modifiers; -use Intervention\Image\Colors\Rgb\Channels\Alpha; -use Intervention\Image\Colors\Rgb\Channels\Blue; -use Intervention\Image\Colors\Rgb\Channels\Green; -use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Drivers\Vips\Core; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\ColorInterface; @@ -74,12 +70,7 @@ private function pad(FrameInterface $frame, SizeInterface $resize, ColorInterfac $resize->height(), [ 'extend' => Extend::BACKGROUND, - 'background' => [ - $bgColor->channel(Red::class)->value(), - $bgColor->channel(Green::class)->value(), - $bgColor->channel(Blue::class)->value(), - $bgColor->channel(Alpha::class)->value(), - ], + 'background' => $bgColor->toArray(), ] ) ); diff --git a/src/Modifiers/RotateModifier.php b/src/Modifiers/RotateModifier.php index 677b8c0..3889a70 100644 --- a/src/Modifiers/RotateModifier.php +++ b/src/Modifiers/RotateModifier.php @@ -4,10 +4,6 @@ namespace Intervention\Image\Drivers\Vips\Modifiers; -use Intervention\Image\Colors\Rgb\Channels\Alpha; -use Intervention\Image\Colors\Rgb\Channels\Blue; -use Intervention\Image\Colors\Rgb\Channels\Green; -use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Drivers\Vips\Core; use Intervention\Image\Exceptions\AnimationException; use Intervention\Image\Exceptions\RuntimeException; @@ -53,21 +49,14 @@ public function apply(ImageInterface $image): ImageInterface */ public function rotate(VipsImage $vipsImage): VipsImage { - $color = $this->driver()->handleInput($this->background); - - $background = [ - $color->channel(Red::class)->value(), - $color->channel(Green::class)->value(), - $color->channel(Blue::class)->value(), - $color->channel(Alpha::class)->value() - ]; + $background = $this->driver()->handleInput($this->background); if (!$vipsImage->hasAlpha()) { $vipsImage = $vipsImage->bandjoin_const(255); } return $vipsImage->similarity([ - 'background' => $background, + 'background' => $background->toArray(), 'angle' => $this->rotationAngle(), ]); }