For larger or more heavily trafficked sites, I imagine this could begin to take a toll on performance if a watermarked image is reassembled every time it's requested.

The next step for this script would be to write the assembled image to a cache directory, similar to how some weblog apps write static copies of their entries. Could be called as a cron job or upon uploading a new image or etc...

Nice script, I'd been contemplating doing something like this both for watermarks and borders.

I would like to use a png with a transparent bg as my watermark image, but the result is black pixels where the watermark's transparency should be. Is this a feature of my version of GD/PHP/whatever, or is it a limitation of the basic script source (as supplied)?

I would like to use a png with a transparent bg as my watermark image, but the result is black pixels where the watermark's transparency should be. Is this a feature of my version of GD/PHP/whatever, or is it a limitation of the basic script source (as supplied)?

Hi Brock, great article, but I was not able to get it to work. Bear with me as I am not very knowlagble with php..

but from your article, I assume we have to save the script (e.g. image.php) and then call the image to be watermarked as image.php?image=pic.jpg

but when i do this i get this error:

<br /><b>Warning</b>: imagecopymerge(): supplied argument is not a valid Image resource in <b>/home/httpd/vhosts/domain.com/httpdocs/image.php</b> on line <b>13</b><br /><br /><b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home/httpd/vhosts/domain.com/httpdocs/image.php</b> on line <b>14</b><br /><br /><b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>/home/httpd/vhosts/domain.com/httpdocs/image.php</b> on line <b>15</b><br />

Heh, I just thinking about watermarking some images of my site that are getting heavily linked to, and voila, where's a quick script.

But this is just a first step. What I really want to do, is develop this script so that it looks at the requests and determines is it from somewhere outside the website? Or is from within? Referrer value is what I want know.

If it's from within, I would rather not "stain" the pictures with my "url" and copy write information. But if it's an external link, well, I'd like to at least let them know from where the picture their viewing, came from.

In The PHP Anthology, HarryF deals with the hot-linking issue using sessions. Good book and base classes to build on, if you do the whole oop php thing. Still having trouble with 5 though (install that is).

I have used this class as a base to what i ended up making an overly robust thumbnail generation monstrosity....but it was fun.

Why does everyone always use pngs in these tutorials, why would I want to use that format when every image I have is either a jpeg or gif! My digital camera only outputs jpeg..... just some food for thought

This script actually doesn't work for me. I'm not sure if Photoshop created .png files have terrible transparency or what, but the watermark uses white where it should be transparent. I have GD2.0+. Any suggestions?