使用php为图像添加“水印" [英] Add 'Watermark' to images with php

查看:34
本文介绍了使用php为图像添加“水印"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,用户可以在其中上传图片...

I have a website where users may upload images...

上传图片后,我需要将我的徽标(水印)添加到图片中.

I need to add my logo (watermark) to the images once they are uploaded.

我该怎么做?

并且水印位于可见的角落是很重要的,例如我见过一些网站会即时生成水印,并将标记放在主图像背景为相同颜色的位置""所以如果你明白我的意思,水印就会很明显.

And it is important that the watermark is in a corner where it will be visible, for example I have seen websites which generates a watermark on the fly, and puts the mark wherever the background of the main image is "the same color" so the watermark sticks out if you know what I mean.

有人有这方面的好教程或文章吗?或者知道我需要在 php 中找到水印位置的任何函数?

Anybody have a good tutorial or article about this? Or know of any function in php which I would need to find the position of the watermark?

推荐答案

A 很好的例子在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);

这篇关于使用php为图像添加“水印"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆