【发布时间】:2020-07-28 04:35:18
【问题描述】:
像这样保存 alpha 混合图像时:
使用imagejpeg(),使用下面的代码,我得到黑色背景。
$sourcePath = "<path to the image above>";
$destPath = "<path to where I want to store it>";
$image = imagecreatefrompng($sourcePath);
imagejpeg($image, $destPath, 85);
我最终得到一个黑色方块。这显然不是我需要的,背景应该是白色的。
我阅读了有关 alpha blending 的内容,并尝试了几件事与 PHP 中的 GD 函数,但我无法完成。也许我应该在保存之前将图像复制到新图像,但我不想这样做。
我的问题是: 使用 PHP GD 函数以适当的白色背景保存上述图像的最简单方法是什么?输出中不需要 alpha 混合,我想要的只是白色背景。
额外问题: 有没有办法检测图像是否具有 alpha 通道?
【问题讨论】:
标签: php image-processing gd alphablending