php - “如何修复”png图像透明度
问题描述
我创建了一个白色背景并添加了一个 PNG 图像。但是在进行跟踪和错误时,png 图像仍然显示浅背景颜色,它应该是 100% 透明且没有背景颜色。
这是我在进行跟踪和错误后的代码,但它仍然在 png 图像中显示浅色背景色。它应该是 100% 透明的。我尝试了很多人,但到目前为止还没有任何解决方案。
$img_h = imagesy($image);
$img_w = imagesx($image);
// create new image (canvas) of proper aspect ratio
$img = imagecreatetruecolor($canvas_w, $canvas_h);
$background = imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $background);
$xoffset = ($canvas_w - $img_w) / 2;
$yoffset = ($canvas_h - $img_h) / 2;
imagealphablending($img, true);
imagesavealpha($img, true);
imagecopyresampled($img, $image, $xoffset, $yoffset, 0, 0, $img_w, $img_h, $img_w, $img_h);
我预计 png 图像将在白色背景上显示为透明。但是代码在 png 图像上添加了浅色背景色。图像预览 -
解决方案
推荐阅读
- mysql - 启动 mysql 服务器后 Docker 容器死机
- spring-boot - 尝试测试数据库时无法加载 ApplicationContext
- java - 如何在 SQLite 中设置数千个数据?
- php - php过滤内容
- git - Windows 10 上的 Git - credential.helper 搞砸了
- r - LaTeX 符号未正确转换为 Moodle
- java - java8 - 使用 ChannelSftp 模式匹配选择最后修改的文件
- angular - 如何使用 Angular 5 将数组对象转换为特定的 JSON 格式?
- sql - 如何在 BCP 到 CSV 时拆分表,我将 RECORD NO 作为唯一键
- android - 我怎样才能删除谷歌默认标记