PHP - 动态添加透明 PNG 到 GIF [英] PHP - Add transparent PNG to GIF dynamically
问题描述
我正在尝试使用 php 代码做水印标记,一切似乎都正常,直到我将透明的 PNG 文件放入 GIF.这会发生什么:
I am trying to do a watermark mark with the php code, and everything seems to work fine, until I put a transparent PNG file to a GIF. This what happens:
所以不是透明的黑色水印,我在顶部得到了这个半纯绿色的东西.水印是
So instead of transparent black watermark, I get this semi solid green thing on the top. The watermark is
我使用以下 php 代码:
I use the following php code:
...
$image = imagecreatefromgif($filepath);;
$watermark_image = imagecreatefrompng($wm_filepath);
imagealphablending($watermark_image, false);
imagesavealpha($watermark_image, true);
imagegif($image, $filepath);
imagedestroy($image);
imagecopy($image, $watermark_image, $offset['x'], $offset['y'], 0, 0, imagesx($watermark_image), imagesy($watermark_image) );
附言我不得不提一下,我尝试使用
p.s. I have to mention that I tried to combine different settings using
imagealphablending()
imagesavealpha()
没有结果
UPD:
现在我将图像保存为 png 文件.我删除了这两行 imagealphablending($watermark_image, false);imagesavealpha($watermark_image, true);
并且它起作用了.但是,PNG 的透明度与 GIF 重叠.imagealphablending($image, true);
没有帮助.我该怎么办?
Now I am saving image as a png file. I deleted these two rows imagealphablending($watermark_image, false); imagesavealpha($watermark_image, true);
and it worked. However, the transparency of PNG is overlapping GIF. imagealphablending($image, true);
didn't help. What shall I do?
推荐答案
GIF 文件限制为 256 种颜色,并且有一种指定为透明的颜色.所以你不能有抗锯齿透明度,也不能有任何类型的抗锯齿.
GIF files are limited to 256 colours and have a single colour designated as transparent. So you can't have antialiased transparency, nor can you have much antialiasing of any kind.
我建议另存为 PNG.
I suggest saving as PNG instead.
这篇关于PHP - 动态添加透明 PNG 到 GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!