示例 #1 使用 imagecopymerge() 创建半透明水印
<?php
// 加载要应用水印的邮票和照片
$im = imagecreatefromjpeg('photo.jpeg');
// 首先,我们手动从 GD 创建邮票图像
$stamp = imagecreatetruecolor(100, 70);
imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF);
imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF);
imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF);
imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0x0000FF);
// 设置邮票的边距并获取邮票图像的高度/宽度
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// 以 50% 的不透明度将邮票合并到我们的照片上
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// 将图像保存到文件并释放内存
imagepng($im, 'photo_stamp.png');
imagedestroy($im);
?>