Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Given rotation background color was ignored when encoding from image
with transparency to image with no alpha channel.
  • Loading branch information
olivervogel committed Jan 5, 2024
1 parent d1b3ed5 commit e86e8d8
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Drivers/Gd/Modifiers/RotateModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Intervention\Image\Drivers\Gd\SpecializedModifier;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Modifiers\FillModifier;

/**
* @method mixed rotationAngle()
Expand All @@ -23,7 +23,7 @@ public function apply(ImageInterface $image): ImageInterface
$background = $this->driver()->handleInput($this->background);

foreach ($image as $frame) {
$this->modifyFrame($frame, $background);
$this->modifyFrame($frame, $background, $image->colorspace());
}

return $image;
Expand All @@ -35,10 +35,14 @@ public function apply(ImageInterface $image): ImageInterface
*
* @param FrameInterface $frame
* @param ColorInterface $background
* @param ColorspaceInterface $colorspace
* @return void
*/
protected function modifyFrame(FrameInterface $frame, ColorInterface $background): void
{
protected function modifyFrame(
FrameInterface $frame,
ColorInterface $background,
ColorspaceInterface $colorspace
): void {
// get transparent color from frame core
$transparent = match ($transparent = imagecolortransparent($frame->native())) {
-1 => imagecolorallocatealpha(
Expand Down Expand Up @@ -74,12 +78,16 @@ protected function modifyFrame(FrameInterface $frame, ColorInterface $background
->rotate($this->rotationAngle() * -1);

// create new gd image
$modified = $this->driver()->createImage(
$modified = imagecreatetruecolor(
imagesx($rotated),
imagesy($rotated)
)->modify(new FillModifier($background))
->core()
->native();
);

// fill new gd with background color
$transColor = $this->driver()->colorProcessor($colorspace)->colorToNative($background);
imagealphablending($modified, true);
imagefill($modified, 0, 0, $transColor);
imagecolortransparent($modified, $transColor);

// retain resolution
$this->copyResolution($frame->native(), $modified);
Expand Down

0 comments on commit e86e8d8

Please sign in to comment.