GIF透明背景变黄
GIF transparent background turned yellow
我尝试了几种解决方案,但没有任何效果。
$srcImage = imagecreatefromgif($_FILES['img']['tmp_name']);
$bg = imagecolorallocatealpha($srcImage, 0, 0, 0, 127);
imagecolortransparent($srcImage, $bg);
imagealphablending($srcImage, false);
imagesavealpha($srcImage, true);
imagegif($srcImage, 't.gif');
结果:
GIF 图像不支持 alpha 通道透明度。
由于您要将现有图像颜色设置为透明,因此您需要在调色板中找到它。您可以使用 imagecolorexact
:
$srcImage = imagecreatefromgif($_FILES['img']['tmp_name']);
$bg = imagecolorexact($srcImage, 204, 168, 46); // RGB here matches the yellowish colour in your image.
imagecolortransparent($srcImage, $bg);
imagegif($srcImage, 't.gif');
结果:
我尝试了几种解决方案,但没有任何效果。
$srcImage = imagecreatefromgif($_FILES['img']['tmp_name']);
$bg = imagecolorallocatealpha($srcImage, 0, 0, 0, 127);
imagecolortransparent($srcImage, $bg);
imagealphablending($srcImage, false);
imagesavealpha($srcImage, true);
imagegif($srcImage, 't.gif');
结果:
GIF 图像不支持 alpha 通道透明度。
由于您要将现有图像颜色设置为透明,因此您需要在调色板中找到它。您可以使用 imagecolorexact
:
$srcImage = imagecreatefromgif($_FILES['img']['tmp_name']);
$bg = imagecolorexact($srcImage, 204, 168, 46); // RGB here matches the yellowish colour in your image.
imagecolortransparent($srcImage, $bg);
imagegif($srcImage, 't.gif');
结果: