开发者

User name as Watermark

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:

User name as Watermark

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 som开发者_如何学Pythoneone knows a way how to solve this and get the same effect on images dynamically.

Thank you very much.


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.


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.


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.


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:

magick convert input.jpg ( -size 960x640 xc:none -font microsoft-new-tai-lue -pointsize 90 -fill black -annotate +120+370 Watermark -blur 0x4 -fill none  -annotate +125+365 Watermark ) -flatten output.png

User name as Watermark

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜