如何在 PNG 上的 PHP GD 中保持透明度
我正在使用此代码:
<?php
list($width, $height, $type, $attr) = getimagesize("terrain.png");
$canvas = imagecreatetruecolor($width, $height);
$src = imagecreatefrompng("terrain.png");
if($_GET['glass'] == 1){
$src2 = imagecreatefrompng("rock.png");
}
imagecopymerge($canvas, $src, 0, 0, 0, 0, $width, $height, 100);
if($_GET['glass'] == 1){
imagecopy($canvas, $src2, 0, 0, 0, 0, 16, 16);
}
imagealphablending($canvas, true);
imagesavealpha($canvas, true);
header("Content-type: image/png");
imagepng($canvas);
imagedestroy($dest);
imagedestroy($src);
?>
Terrain.png 位于 http://hogofwar.co.uk /experiment/mc/terrain.png(透明)
使用 GD 时如何保持透明度?
I am using this code:
<?php
list($width, $height, $type, $attr) = getimagesize("terrain.png");
$canvas = imagecreatetruecolor($width, $height);
$src = imagecreatefrompng("terrain.png");
if($_GET['glass'] == 1){
$src2 = imagecreatefrompng("rock.png");
}
imagecopymerge($canvas, $src, 0, 0, 0, 0, $width, $height, 100);
if($_GET['glass'] == 1){
imagecopy($canvas, $src2, 0, 0, 0, 0, 16, 16);
}
imagealphablending($canvas, true);
imagesavealpha($canvas, true);
header("Content-type: image/png");
imagepng($canvas);
imagedestroy($dest);
imagedestroy($src);
?>
Terrain.png is at http://hogofwar.co.uk/experiment/mc/terrain.png (which is transparent)
How do I preserve the transparency when using GD?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试
您可以检查更多详细信息,
http://www.php。 net/manual/en/function.imagecolortransparent.php
You can try
You can check for more details,
http://www.php.net/manual/en/function.imagecolortransparent.php
试试这个:
完成...
Try this:
Done...