php GD 创建透明png图像
我正在尝试创建一个透明的 png 图像,并将各种其他 png 和 jpg 分层以创建具有透明度的最终 png。我在创建最初的空透明 png 时遇到问题。它目前有白色背景。
谁能指出我正确的方向。这是我到目前为止的代码...
$image = imagecreatetruecolor(485, 500);
imagealphablending($image, false);
imagesavealpha($image, true);
$col=imagecolorallocatealpha($image,255,255,255,127);
imagefill($image, 0, 0, $col);
//imagefilledrectangle($image,0,0,485, 500,$col);
/* add door glass */
$img_doorGlass = imagecreatefrompng("glass/$doorStyle/$doorGlass.png");
imagecopyresampled($image, $img_doorGlass, 106, 15, 0, 0, 185, 450, 185, 450);
/* add door */
$img_doorStyle = imagecreatefrompng("door/$doorStyle/$doorStyle"."_"."$doorColor.png");
imagecopyresampled($image, $img_doorStyle, 106, 15, 0, 0, 185, 450, 185, 450);
$fn = md5(microtime()."door_builder").".png";
if(imagepng($image, "user_doors/$fn", 1)){
echo "user_doors/$fn";
}
imagedestroy($image);
I'm trying to create a transparent png image and layer various other pngs and jpgs to create a final png with transparency. I'm having trouble creating my initial empty transparent png. It currently has a white background.
Can anyone point me in the right direction. This is my code so far...
$image = imagecreatetruecolor(485, 500);
imagealphablending($image, false);
imagesavealpha($image, true);
$col=imagecolorallocatealpha($image,255,255,255,127);
imagefill($image, 0, 0, $col);
//imagefilledrectangle($image,0,0,485, 500,$col);
/* add door glass */
$img_doorGlass = imagecreatefrompng("glass/$doorStyle/$doorGlass.png");
imagecopyresampled($image, $img_doorGlass, 106, 15, 0, 0, 185, 450, 185, 450);
/* add door */
$img_doorStyle = imagecreatefrompng("door/$doorStyle/$doorStyle"."_"."$doorColor.png");
imagecopyresampled($image, $img_doorStyle, 106, 15, 0, 0, 185, 450, 185, 450);
$fn = md5(microtime()."door_builder").".png";
if(imagepng($image, "user_doors/$fn", 1)){
echo "user_doors/$fn";
}
imagedestroy($image);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在每个新图层上设置
imagealphablending($image,true);
。试试这个:
Set
imagealphablending($image,true);
on each new layer.Try this:
这段代码对我有用:
This code worked for me:
尝试更换
$col=imagecolorallocatealpha($image,255,255,255,127);
与
$col=imagecolorallocate($image,255,255,255);
并尝试取消注释
imagefilledrectangle
行。我可以测试这段代码 - 给我图片:)
Try to replace
$col=imagecolorallocatealpha($image,255,255,255,127);
with
$col=imagecolorallocate($image,255,255,255);
and try to uncomment
imagefilledrectangle
line.I can test this code - give me the pictures :)