我有脚本添加水印(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)
发布于 2012-04-20 15:18:59
感谢你们的帮助- 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);发布于 2012-04-19 14:27:52
您的输出图像格式为jpeg。Jpeg不支持透明。将输出格式更改为png。
也建议你使用图像魔法。Gd是非常原始的。
发布于 2012-04-19 14:27:28
当从PNG创建带有alpha图的PNG图像时,不要忘记这些函数:
imagealphablending($stamp,false);
imagesavealpha($stamp,true);看看有没有什么不同?
https://stackoverflow.com/questions/10222664
复制相似问题