Watermarking is a popular method to protect digital photos from being copied by the picture thieves on the net. Using PHP we can do the same. Here we use a transparent PNG image as Watermark template, we then merge it with image to create a permanent watermark.
In most scenarios people want to resize uploaded image using HTML form and then watermark it on the fly. So in this article, we will do the same. We upload an image, resize it and then watermark it with our PNG file.
Picture : Thomas Leth-Olsen
If you look at my previous resize snippet, you’ll realize that I have made a slight modification to the code. This snippet typically does the same thing, it resizes uploaded image. But after modification, now it adds a watermark to all resized images. Let’s create an upload page using HTML below.
The slight modification in previous PHP snippet I talked about above is that I have added PHP imagecopy() in this snippet. What it actually does is that it copies defined portion of source image to the destination image. So, basically we copy and merge PNG watermark image with the uploaded image.
Take a look at example below, the code first calculates center position of watermark image using width and height of destination and watermark images, and then using PHP imagecopy() it merges watermark image to the destination image.
If you are clear on the example above, take a look at the complete PHP code below, we call PHP imagecopy() function after the image is resized, but before saving the image.
You can download example files by clicking download button below, and play a bit with it on your server, all the best!