PHP创建的水印看起来很奇怪

时间:2012-04-19 06:22:10

标签: php watermark

我有脚本添加水印(PNG,透明)到图像(JPG)。带有捕获效果很好 - 在某种程度上水印会改变颜色并使其不透明。 这是我用来添加水印的代码:

$im = imagecreatefromjpeg('../../pics/'.$ran.'_large.jpg');
$stamp = imagecreatefrompng('a.png');

$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 70);

// Save the image to file and free memory
imagejpeg($im, '../../pics/'.$ran.'_large.jpg');
imagedestroy($im);

Image with watermark after PHP generates it (wrong way)

3 个答案:

答案 0 :(得分:1)

您的输出图像格式为jpeg。 Jpeg不支持透明度。将输出格式更改为png。

还建议您使用图像魔术。 Gd非常原始。

答案 1 :(得分:0)

在使用PNG创建PNG图像时,不要忘记这些功能:

imagealphablending($stamp,false);
imagesavealpha($stamp,true);

看看它是否有任何区别?

答案 2 :(得分:0)

谢谢你的帮助 - I found answer in this site

$im = imagecreatefromjpeg('../../pics/'.$ran.'_large.jpg');
$stamp = imagecreatefrompng('a.png');

imagealphablending($im, true);

$marge_right = 10;
$marge_bottom = 10;

$sx = imagesx($stamp);
$sy = imagesy($stamp);

$offset = 10;

imagecopy($im, $stamp, imagesx($im) - imagesx($stamp) - $offset, imagesy($im) - imagesy($stamp) - $offset, 0, 0, imagesx($stamp), imagesy($stamp));
// Save the image to file and free memory
imagejpeg($im, '../../pics/'.$ran.'_large.jpg');
imagedestroy($im);