我有PHP上传脚本,我需要在用户上传后在图像上添加水印。
我尝试了很多方法,但最后都给了你预览图像的PHP路径
我需要在此链接http://php.net/manual/en/image.examples-watermark.php中执行相同操作,但请将其保存到实际图像中以获得此类图像路径" my_new_image_with_watermark.jpg" 不仅仅是file.php
代码实际上是:
<?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);
?>
感谢
答案 0 :(得分:2)
而不是:
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
写:
$filename = '/foo/bar.png';
imagepng($im, $filename);
imagedestroy($im);