Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Image transparency was replaced by black color, when rendered as a
format with no alpha channel support.
  • Loading branch information
olivervogel committed Jan 5, 2024
1 parent ceacb64 commit d1b3ed5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Drivers/Gd/Modifiers/ResizeModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ private function resizeFrame(FrameInterface $frame, SizeInterface $resizeTo): vo
imagefill($modified, 0, 0, $transColor);
imagecolortransparent($modified, $transColor);
} else {
imagealphablending($modified, false);
$transColor = imagecolorallocatealpha($modified, 255, 255, 255, 127);
imagealphablending($modified, true);
imagefill($modified, 0, 0, $transColor);
imagecolortransparent($modified, $transColor);

imagealphablending($modified, true);
imagesavealpha($modified, true);
}

Expand All @@ -64,6 +69,7 @@ private function resizeFrame(FrameInterface $frame, SizeInterface $resizeTo): vo
$frame->size()->height()
);


// set new content as recource
$frame->setNative($modified);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Drivers/Imagick/Encoders/JpegEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ public function encode(ImageInterface $image): EncodedImage
$compression = Imagick::COMPRESSION_JPEG;

$imagick = $image->core()->native();
$imagick->setImageBackgroundColor('white');
$imagick->setBackgroundColor('white');
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
$imagick->setCompressionQuality($this->quality);
$imagick->setImageCompressionQuality($this->quality);
$imagick->setImageBackgroundColor('white');
$imagick->setBackgroundColor('white');
$imagick->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);

return new EncodedImage($imagick->getImagesBlob(), 'image/jpeg');
}
Expand Down

0 comments on commit d1b3ed5

Please sign in to comment.