允许用户在PHP中添加自己的水印

时间:2013-07-07 16:11:56

标签: php image file-upload watermark

允许用户添加自己的水印和放大器是否可以我应该使用什么过滤器来上传正确的文件。水印只是图像还是文字?

1 个答案:

答案 0 :(得分:0)

我个人认为没有必要让用户将自己的水印添加到图像中。但这取决于您的要求。可以使用alpha通道使用PHP完成。

来自PHP Manual的一个很好的例子:

<?php
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');

// Set the margins for the stamp and get the height/width of the stamp image
$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);
imagedestroy($im);
?>

示例输出:

enter image description here

希望这有帮助!