6

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: alt text

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.

Justin Johnson
  • 30,978
  • 7
  • 65
  • 89
moonwalker
  • 485
  • 2
  • 6
  • 20

5 Answers5

11

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.

PleaseStand
  • 31,641
  • 6
  • 68
  • 95
  • Thanks for the reply. As I mentioned before, I already know how to add watermarks dynamically to an image. I want to take it a step further and dynamically create a PNG with the transparency and shadow effects as you see here above for each registered user. – moonwalker Nov 14 '10 at 18:07
  • Sorry, didn't see what you meant the first time. Thanks a lot, i'll give this a shot! – moonwalker Nov 14 '10 at 18:13
2

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.

Ryan Doom
  • 2,407
  • 1
  • 16
  • 13
  • Thank you for your reply. As I mentioned before I already know how to this. I need now to dynamically create the "watermark" PNG file for each user with PHP. :) – moonwalker Nov 14 '10 at 18:08
0

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.

Brad
  • 159,648
  • 54
  • 349
  • 530
0

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.

Sparr
  • 7,489
  • 31
  • 48
  • That's the whole idea. I don't know how to generate a PNG file with transparency and shadow effect. The image is created once when the user is registered (they can't change their user name) – moonwalker Nov 14 '10 at 18:10
0

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
focog77269
  • 104
  • 5