.htaccess Wrappers with PHP
(Page 5 out of 6)This last demonstration of an htaccess wrapper is something that I think most people with content sites have a use for. On the Internet, people steal stuff. Theft of HTML source code is a nuisance, sure, but the lifting of images is more common. Someone likes a logo on your page, or an e-book cover, or a picture of a physical product you're selling, and it becomes theirs to use.
A practical way to keep this from happening is to add a watermark to all your images, which is your logo or name on a corner somewhere, forcing anyone who takes your graphic to either unwillingly give you credit, or chop off a part of that picture.
Lucky for us, PHP has a set of functions to handle images, and in version 4.3 and above, it's included by default. Wrappers come in handy here because you might have an entire site full of images and would rather not spend three weeks watermarking tons of images by hand. Maybe you just don't want to have to juggle two sets of images, one watermarked and one normal.
Download this script from: http://www.jumpx.com/tutorials/wrapper/watermark.zip
The only files you need to worry about in that zip are htaccess.txt and wrapper.php. Upload them to a folder called "watermark", chmod htaccess.txt to 0755 and rename to ".htaccess".
The file wrapper.php remain as is. I've put comments in the file regarding most of what it does, so if you're curious go ahead and take a peek.
What the script does is this: It figures out the original image that was supposed to be called. Then it loads the watermark, which I've set in wrapper.php to be "watermark.png" which is just a PNG image containing the text "THIS IS WATER MARKED". The watermark is placed on top of the original, in the lower right corner, and output in the same format (i.e., JPEG) as the original.
You can tell the difference by looking at these two images:
http://www.jumpx.com/tutorials/wrapper/thomas.jpg
http://www.jumpx.com/tutorials/wrapper/thomas-watermarked.jpg
I've included several types of images (GIFs, JPGs, and PNGs) in the zip file for you to test out. Once you've got everything setup, upload those images and see how they look with the watermark.
This script will work with GIFs, JPEGs, and PNGs. Due to a patent issue (which expires worldwide in July 2004) GIFs can only be read, and not output. To make up for this, any of your GIFs will be output as PNGs, which should still work.