如何给图片加水印?
如何在不影响源图像的情况下在图像上添加水印。
$SourceFile = '/uploadedimage/gallery/thumble/';
$DestinationFile = '/uploadedimage/gallery/thumble/image-watermark.jpg';
$WaterMarkText = 'Copyright appsbee.com';
watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile);
function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) {
list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($SourceFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
$black = imagecolorallocate($image_p, 0, 0, 0);
$font = 'arial.ttf';
$font_size = 10;
imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText);
if ($DestinationFile<>'') {
imagejpeg ($image_p, $DestinationFile, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($image_p, null, 100);
};
imagedestroy($image);
imagedestroy($image_p);
};
如果我这样做,缩略图文件夹中存在的图像就会受到影响。
How to put water mark on image without affecting the source image.
$SourceFile = '/uploadedimage/gallery/thumble/';
$DestinationFile = '/uploadedimage/gallery/thumble/image-watermark.jpg';
$WaterMarkText = 'Copyright appsbee.com';
watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile);
function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) {
list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($SourceFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
$black = imagecolorallocate($image_p, 0, 0, 0);
$font = 'arial.ttf';
$font_size = 10;
imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText);
if ($DestinationFile<>'') {
imagejpeg ($image_p, $DestinationFile, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($image_p, null, 100);
};
imagedestroy($image);
imagedestroy($image_p);
};
If I do this the image which are present on thumble folder are effected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用这个类,在添加水印之前只需复制原始图像即可。
这就是如何使用它
Use this class, before putting water mark just make the copy of original image.
and this is how to use it
要在不影响实际图像的情况下执行此操作,只需添加包含透明图像的 HTML 层即可。但这作为一种保护手段毫无用处,因为每个拥有一点点技术知识的人都可以在几秒钟内获取原始图像。
Doing this without affecting the actual image is possible only by adding a HTML layer containing a transparent image. That is pretty useless as a means of protection though, because everyone with a tiny bit of technical knowledge can fetch the original image in seconds.
如果您不想影响源图像,那么我建议您将透明图像放在 HTML 中图像上方的绝对定位 div 中。这意味着您不必在每次页面加载时处理图像(因为您想保持原始图像完整),并且不必费力存储额外的图像。
If you don't want to affect the source image, then I'd recommend putting a transparent image in an absolutely positioned div over the image in your HTML. This means you don't have to process an image on each page load (because you want to keep the original intact), and you don't have to mess about with storing an extra image.
使用GD图像库: http://php.net/manual/en/book.image .php
这样我就可以创建图像的网络水印版本并存储源图像。
除非您打算即时添加水印,在这种情况下,我不确定您是否可以轻松做到这一点。
Using the GD image library: http://php.net/manual/en/book.image.php
This way I would create a web watermark version of the image and also store the source image.
Unless you mean to add a watermark on the fly in which case I'm not sure you can that easily.
从第一眼看来,我认为如果您没有向函数提供目标文件名,则这段代码不会影响源文件。
From the first sight, I think this code will not affect the source file if u didn't provide a destination file name to the function.