6 times 9 Watermark

About

A PHP script to add a watermark image to normal images (to identify the image's source) while keeping the location of the originals hidden, and without the need to manually "Photoshop" the images to add the watermarks.

Example

Original Image (from Flickr)

Pebbles

With Watermark

Watermarked Pebbles

Invalid Image

Invalid Image

Invalid Watermark

Invalid Watermark

Using

Initial Setup

Once you have uploaded the script to the server, there are a couple of things to do before you use it.

Firstly create the watermark image. This can be done in your graphics package of choice, but the file must be a PNG. For example, this is the image used in the Example section:

6 times 9 Logo

Secondly, edit the "Setup" section near the top of 6x9watermark.php:

  • $padding is the number of pixels between the watermark and the outside of the image.
  • $watermark is the path to watermark image, relative to the root directory. It must include the leading slash.
  • $path is the path to 6x9watermark.php itself, relative to the root directory. It must include the leading and trailing slashes but must not include the actual filename.

After that you should be all set.

Implementation

Once you've uploaded and set up the script, add:

<?php include '6x9watermark.php'; ?>

to the top of all pages where you want to use it. Obviously the pages must have a ".php" extension and the path in the "include" must match the actual location of the script.

Then, instead of this:

<img src="/path/to/image.jpg" alt="An Image" />

do this:

<img src="<?php echo watermark("/path/to/image.jpg"); ?>" alt="An Image" />

The path in the function must either be a full URL (http:// etc.) or the path to the image relative to the root directory of the website.

Invalid Images

If the image or the watermark are not valid, then the image returned will be an image informing you of this fact, as in the Example section above.

How It Works

The script uses the data: URI scheme to output the images, except in Internet Explorer (which doesn't support it yet) where a less elegant solution must be employed.

The image and the watermark are loaded and combined using PHP functions. Then, because of how PHP works, the combined image has to be stored to a temporary file and then read back. It is then appropriately encoded for "data:" and the finished URI is returned.

Technical explanation: The images are Resources, but the encoding requires a String. Going via a temporary file seemed to be the simplest way of converting it.

Download

To download 6 times 9 Watermark just right-click and choose "Save As" (or the equivalent for your Operating System/Web Browser).

The current version is Alpha (2008-03-13) - No changelog.

There's now an RSS feed for easy notification of the infrequent updates to all 6 times 9 projects.

Feedback

I'd like to hear what you have to say about this; I've only been able to test it in IE, Firefox, and Opera in Windows - I have no idea if it'll work on a Mac, for example...

If you have any comments, compliments, or suggestions feel free to email me and let me know.