Skip to content

Commit

Permalink
Refactor color channel extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 7, 2025
1 parent de515eb commit c14d38e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
11 changes: 1 addition & 10 deletions src/Modifiers/ContainModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
]
)
);
Expand Down
11 changes: 1 addition & 10 deletions src/Modifiers/PadModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
]
)
);
Expand Down
15 changes: 2 additions & 13 deletions src/Modifiers/RotateModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
]);
}
Expand Down

0 comments on commit c14d38e

Please sign in to comment.