我有一个网站,用户可以上传图片…
我需要添加我的标志(水印)的图像,一旦他们被上传。
我如何做到这一点呢?
重要的是,水印是在一个角落,它将是可见的,例如,我看到的网站上生成一个动态水印,并将标记的地方,主图像的背景是“相同的颜色”,所以水印突出,如果你明白我的意思。
有没有人对此有很好的教程或文章?或者知道php中的任何函数,我需要找到水印的位置?
发布于 2010-02-10 15:42:00
PHP手册中的good example:
// 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);
发布于 2014-11-15 04:08:39
使用此函数
水印图片类型必须为"png“
function watermark_image($target, $wtrmrk_file, $newcopy) {
$watermark = imagecreatefrompng($wtrmrk_file);
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
$img = imagecreatefromjpeg($target);
$img_w = imagesx($img);
$img_h = imagesy($img);
$wtrmrk_w = imagesx($watermark);
$wtrmrk_h = imagesy($watermark);
$dst_x = ($img_w / 2) - ($wtrmrk_w / 2); // For centering the watermark on any image
$dst_y = ($img_h / 2) - ($wtrmrk_h / 2); // For centering the watermark on any image
imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h);
imagejpeg($img, $newcopy, 100);
imagedestroy($img);
imagedestroy($watermark);
}
watermark_image('image_name.jpg','watermark.png', 'new_image_name.jpg');
发布于 2012-10-12 00:13:06
我找到了一个更好的解决方案,通过.htaccess动态添加水印,你可以在这里找到教程:
Add watermark to images through htaccess
上传自定义.htaccess文件、watermark.php加密文件和watermark.png图像后,文件夹及其子文件夹中的所有图像都将显示水印,但您仍会将原始文件保留在服务器中。
希望这对别人有帮助,就像对我有帮助一样。
https://stackoverflow.com/questions/2235152
复制相似问题