One of the things you can do with PHP's many functions for image handling and manipulation is create an image watermarking class. This will allow you to add a watermark to images, which can be useful for a number of purposes. Keep reading to learn how.
A downloadable file for this article is available here.
PHP features a wide array of functions for image handling and manipulation. In today’s article, we are going to use those functions to create an image watermarking class. This class will operate on two images: a source image and a watermark. As an optional third parameter our class will also accept an alpha value – allowing our watermark to contain alpha transparency.
This should be an enjoyable exercise, but hopefully it will also be one that is very useful. For example, let us imagine a scenario where you are hired to create a searchable inventory system for a stock photography website. Obviously you will need to protect your client’s photographs –- offering full quality images only to paying customers. To do this, you could create multiple copies of each image, or you could simply implement a watermarking script like the one we are about to create. This script could then add a watermark to any unpurchased images, while leaving those that have been purchased unmarked.
Perhaps you can already think of a situation where you could use this type of script – perhaps not. In either case, developing it will be a good learning excercise. Most important, it will be fun! So let’s get started.