首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gif图像上的WaterMarking

gif图像上的WaterMarking
EN

Stack Overflow用户
提问于 2014-04-14 14:55:47
回答 1查看 859关注 0票数 2

因此,我在Gif image.here上对png图像进行水印,这是我的代码:

代码语言:javascript
复制
<?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是许多图像的组合,但有什么解决办法,我们可以把图像与正常行为。我也看到了一些在线水印工具,但它们也有同样的问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-14 20:14:03

您可以将gif转换为真实的彩色图像。试试这个:

代码语言:javascript
复制
<?php
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('add_item.png');// watermark image
$im = imagecreatefromgif('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);

// Convert gif to a true color image
$tmp = imagecreatetruecolor(imagesx($im), imagesy($im));
$bg = imagecolorallocate($tmp, 255, 255, 255);
imagefill($tmp, 0, 0, $bg);
imagecopy($tmp, $im, 0, 0, 0, 0, imagesx($im), imagesy($im));
$im = $tmp;

// 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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23063377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档