mirror of
https://github.com/Intervention/image.git
synced 2025-07-31 11:00:12 +02:00
Fix bug in cloner transparency (#1388)
If an image was cloned with cloneEmpty() and a fully transparent color for exampe "rgba(255, 255, 255, 0)" the turned out as white background when encoding formats with only binary transparency like GIF. This patch sets the background color as fully transparent if it has an alpha channel value is below `0.5`.
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
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,6 +68,12 @@ class Cloner
|
||||
imagealphablending($clone, true);
|
||||
imagesavealpha($clone, true);
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
return $clone;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user