dongle19863 2017-01-05 18:19
浏览 113

透明图像PHP上的透明图像

I'll explain a bit of my situation.

We got an island with cities. These could be:

  • Owned by my alliance
  • Owned by an enemy
  • Owned by nobody (free)

So we got 3 "cities"-images and an island image, looks like this:

Island

No owner

Alliance

Enemy

Now we want to put these cities images on the island image. For example, we put a city owned by nobody on the island like this:

<?php
// Get image
$im = imagecreatefrompng('island.png');
imagealphablending($im,true);

// Get our "Free-city-position" image
$stamp = imagecreatefrompng('free.png');

$pos_x = 190 - 15; // Position X = 190 - the half of the free.png image = 30 / 2 = 15
$pos_y = 225 - 15;// Position Y = 225 - the half of the free.png image = 30 / 2 = 15

imagealphablending($stamp,true);
imagecopy($im, $stamp, $pos_x, $pos_y, 0, 0, imagesx($stamp), imagesy($stamp));

// Output image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

And now there is our problem: The city image is not transparent on the island image! It looks like this: Island with city

I thought imagealphablending should do the trick, but unfortunately, it doesn't.

How can we get the transparant city image on the island?

  • 写回答

2条回答 默认 最新

  • douanye8442 2017-01-05 18:46
    关注

    Taken from PHP's comment on GD functions :

    If you are trying to copy a transparant image on to another image, you might assume that you should apply the ImageAlphaBlending function to the image that has the transparancy, the source image. In reality, you must apply the ImageAlphaBlending function to the destination image. Basically it's saying, "make the specified image respect transparancy".

    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入