From 6a4607dd9a4db77b838bf4426d95e9cd532310e2 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 11 Aug 2024 11:59:10 +0200 Subject: [PATCH] Adjust logic of cloner transparency application --- src/Drivers/Gd/Cloner.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Drivers/Gd/Cloner.php b/src/Drivers/Gd/Cloner.php index d29d9add..8723006a 100644 --- a/src/Drivers/Gd/Cloner.php +++ b/src/Drivers/Gd/Cloner.php @@ -5,6 +5,7 @@ namespace Intervention\Image\Drivers\Gd; use GdImage; +use Intervention\Image\Colors\Rgb\Channels\Alpha; use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Geometry\Rectangle; @@ -67,7 +68,9 @@ public static function cloneEmpty( imagealphablending($clone, true); imagesavealpha($clone, true); - if ($background->isClear()) { + // set background image as transparent if alpha channel value if color is below .5 + // comes into effect when the end format only supports binary transparency (like GIF) + if ($background->channel(Alpha::class)->value() < 128) { imagecolortransparent($clone, $processor->colorToNative($background)); }