将多个透明 PNG 合并为一个
我正在用弯曲的边框制作广告。
以下是广告示例:http://imageshack.us/f/20/4e5f5fe94b327new60seciq.png/
我正在尝试复制在 Photoshop 中完成的操作,将一个放在另一个之上。这是我正在使用的代码:
// create destination canvas
$dest_img = imagecreatetruecolor(176, 75);
// Make the background transparent
$black = imagecolorallocate($dest_img, 0, 0, 0);
imagecolortransparent($dest_img, $black);
imageAlphaBlending($dest_img, false);
imageSaveAlpha($dest_img, true);
// copy ad into destination
imagecopy($dest_img, $ad_image, 0, 0, 0, 0, 176, 75);
// copy frame onto first half of image
imagecopy($dest_img, $curve_image, 0, 0, 0, 0, 88, 75);
发生的情况是最后一个副本(框架)优先,我没有看到广告,而是看到了一个透明的块。这是 GD 正在做的事情的放大图像:
http://imageshack.us/f/ 684/unled1to.png/
我希望有一个简单的解决方案可以让下层保持可见 - 如果没有,我想我将不得不编写一个函数并逐像素进行比较......
if (bottom_px == trans && top_px == trans) {
dest_px = trans;
}
else {
dest_px = top_px;
}
I am framing ads with a curved border.
Here is a sample ad: http://imageshack.us/f/20/4e5f5fe94b327new60seciq.png/
I am trying to replicate what would be done in Photoshop, place one on top of the other. Here is the code I'm using:
// create destination canvas
$dest_img = imagecreatetruecolor(176, 75);
// Make the background transparent
$black = imagecolorallocate($dest_img, 0, 0, 0);
imagecolortransparent($dest_img, $black);
imageAlphaBlending($dest_img, false);
imageSaveAlpha($dest_img, true);
// copy ad into destination
imagecopy($dest_img, $ad_image, 0, 0, 0, 0, 176, 75);
// copy frame onto first half of image
imagecopy($dest_img, $curve_image, 0, 0, 0, 0, 88, 75);
What is happening is that the last copy to take place (the frame) is taking priority and instead of seeing the ad, im getting a transparent block. Here is a blown up image of what GD is doing:
http://imageshack.us/f/684/unled1to.png/
I'm hoping there is a simple solution to get the lower layer to remain visible - if not I think I will have to write a function and go pixel by pixel and compare...
if (bottom_px == trans && top_px == trans) {
dest_px = trans;
}
else {
dest_px = top_px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
imagealphablending
设置为 true。手册中强调了:另外,您实际上并没有将背景着色为透明。您只是告诉
$black
是透明的。相反,应将imagefill
与imagecolorallocatealpha
结合使用:Set
imagealphablending
to true. From the manual, emphasis added:Also, you are not actually coloring the background transparent. You are just telling that
$black
is transparent. Instead, useimagefill
withimagecolorallocatealpha
: