Why So Scared

A blog about; Programming, Music and Random Stuff

PHP Image Watermarking

If you’ve ever wanted to watermark images on your website, this neat script will be just what you’re looking for.

Warez-DnB watermark

The Warez-DnB Watermark

The watermark image is held in a separate file, rather than having to actually edit each image with your watermark, save and upload, this script will serve the watermark to the user on the image as  and when its requested.

I like this approach to watermarking because no only is it much easier than editing each picture individually it also means with FTP access you still have an original image intact without the watermark. Only users connecting via HTTP will see the watermarked version.

This also allows for ultimate flexibility, if for whatever reason you decide to change the site logo, its as simple as replacing one image file and every image hosted will have the new watermark.

Save this simple PHP script below as “watermark.php

The final stage is uploading the watermark.php file and image into the directory you want watermarking to take place. In the case of Warez-DnB this is in http://www.warez-dnb.com/grabs/

The final step is an edit to the .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(gif|jpeg|jpg|png)$ watermark.php [QSA,NC]

If you wanted to use the directory /images/ you should now have

/images/watermark.php
/images/watermark.png
/images/.htaccess

Now start uploading some images to /images/ and all is done.

Example http://www.warez-dnb.com/grabs/71a3007301fbd4349e99d85d7afd1c3b.png

Enjoy :)

posted by Juo in tidbit and have Comments (2)
Tags: ,

2 Responses to “PHP Image Watermarking”

  1. Tim Russell says:

    Hey man great post, we rele need to change that logo tho.

  2. Juo says:

    Yeah we do, we shall get on it over summer :)

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment