【发布时间】:2014-04-14 14:55:47
【问题描述】:
所以我在 Gif 图像上为 png 图像添加水印。这是我的代码:
<?php
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('add_item.png');// watermark image
$im = imagecreatefromjpeg('gif_image.gif');// source image
$image_path = "/opt/lampp/htdocs/my/Harshal/watermarking/".time().".png";
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
//header('Content-type: image/png');
imagepng($im,$image_path);
imagedestroy($im);
?>
我的代码工作正常,它在 gif 图像上为 png 图像加水印,但问题是: 水印png图像的后面是白色背景,而不是其他图像的透明背景。
你们能告诉我为什么只有 gif 图像有问题吗?
查看生成的图像。
我知道 Gif 是许多图像的组合,但有什么解决方案可以让图像具有正常行为。? 我也看到了一些在线水印工具,但它们也有同样的问题。
【问题讨论】:
-
如果您的PNG中设置为“透明”的颜色与您的GIF不同,它将显示为不透明。
-
这里也是一个很好的例子:Link