用户名作为水印
好吧,我搜索了互联网和 stackoverflow,但我似乎找不到我的问题的答案。
我需要动态地为用户上传的图像添加水印,但我不想只在图像上应用文本。我需要一个像这样的真实水印:
我实现这种效果的唯一方法是使用 Photoshop,添加阴影并将填充减少到 0%。但如果我的网站有 200 个上传图像的用户访问,我就无法为他们每个人制作一个带有他们的用户名的新 PNG 文件。这就是为什么我正在寻找这个问题的动态解决方案。
我已经找到了如何将 png 文件作为水印添加到图像中的课程,但就像我之前说过的,如果我的网站被很多用户访问,这将不起作用。
我希望有人知道如何解决这个问题并动态地在图像上获得相同的效果。
非常感谢。
Ok, I searched the internet and stackoverflow but I just can't seem to find an answer for my problem.
I need to watermark images uploaded by users dynamically, but I don't want just text applied on an image. I need a real watermark like this:
The only way I can achieve this effect is by using Photoshop, adding shadow and decreasing the filling to 0%. But if my site is visited by 200 users who upload their images, I just can't make for everyone of them a new PNG file with their user name. That's why I'm looking for a dynamic solution for this problem.
I already found classes how to add a png file as a watermark to images, but like I said before this won't work if my site is visited by a lot of users.
I hope someone knows a way how to solve this and get the same effect on images dynamically.
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
ImageMagick图像处理库的文档包含这样一个透明水印示例。即使您想使用 GD 而不是 ImageMagick,它也可能会让您了解如何操作。
The documentation of the ImageMagick image processing library includes such a transparent watermark example. Even if you would like to use GD instead of ImageMagick, it might give you an idea of how to do it.
您可以使用 imageMagick 通过 PHP 来完成此操作。谷歌搜索一下 PHP imagemagick 水印,这个线程可能会帮助一些人:
http://www.imagemagick.org/discourse-server /viewtopic.php?f=1&t=17067
您本质上是想为水印制作一个 PNG 文件。 PNG 将允许 alpha 透明度,您可以获得投影效果等。
然后,这将应用于您的 JPG 图像,最终的带水印的 JPG 图像将在其上添加您的 PNG。
应该有效。
You can use imageMagick to do this with PHP. Do some Googling for PHP imagemagick watermarking, this thread may help some:
http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=17067
You essentially want to make a PNG file of your watermark. The PNG will allow for alpha transparency and you can get your drop shadow effect etc.
This will then be applied to your JPG image, and a final watermarked JPG image will be made with your PNG added on top of it.
Should work.
这里的其他答案都是很好的答案,但我想提出一个替代方案。
您可以为动态构建要执行的 GIMP,这为您提供了大量的灵活性。对于简单的水印来说,这有点过分了,但如果您需要进行一些更复杂的图像处理,它绝对是一个选择。 CoolText.com 就是执行此操作的网站示例。
同样的方法也应该适用于 Photoshop。事实上,您可能可以使用 PHP 实例化 Photoshop 的COM 接口。
再次强调,我不建议将其用于基本水印...只是如果您需要比 ImageMagick/GD 提供的功能更多的功能。
The other answers here are great answers, but I wanted to throw in an alternative.
You can dynamically build scripts for the GIMP to execute, which gives you tons of flexibility. This is way overkill for a simple watermark, but if you needed to do some more complex image processing, it is definitely an option. CoolText.com is an example of a website that does this.
The same approach should work in Photoshop as well. In fact, you could probably instantiate Photoshop's COM interface with PHP.
Again, I don't recommend this for basic watermarking... just if you need more functions than what is provided with ImageMagick/GD.
对于其他答案,我将补充一点,您不应该即时生成图像。如果水印是按用户名设置的,请在用户注册您的网站(或更改用户名)时生成一次水印文件,然后使用该文件作为上传图像的覆盖层。这将节省大量的CPU时间。
To the other answers I will add that you should not be generating the image on the fly. If the watermark is by username, generate the watermark file once when the user registers for your site (or changes their username), then use that file as an overlay for the uploaded images. This will save a lot of CPU time.
使用以下命令:
Use the following command: