Watermark images for your gallery

Recently I had to find an answer of the question “How can I include Creative Commons License watermark on all of the images in my gallery“? I have my blog licensed in by-nc-nd CC license and I wanted all the images to be licensed in CC as well.

I had two options:

* Downloading all my images, watermarking them with some Free Software like Picture Shark and returning them to the gallery. Quite sick and costly solution, having in mind that I have about 400 images alreaedy there and I have to take care to watermark any of my images, which I upload in the future.
* Modifying my gallery in order to display any image from my albums with a given watermark. This seemed to be the right solution – costly at first sight, but cheaper if you look in a perespective.

After some evaluation, I decided to go with the second solution, and started to search for solution of my problem. Coppermine Gallery forum search seemed to produce some sufficient results, but the solution there was quite lenghty and I decided to postpone implementing it.

Instead I focused at the problem as it was seemed in BGDev.Org forum (in Bulgarian!). It seems that the user __webdev__ was proposing a solution of the problem. I decided to give a try to that solution, as it seemed to be the most suitable to me.

The idea in general is:

* You place a .htaccess file in each directory of your gallery, on which images you would like to place the watermark.
* You forward all images’ requests to a script, which generates the image with watermark.

Simple and effective – at least from the end-user’s point of view. It gives some load on the server, but who cares 🙂 ? For simple and not-so-visited gallery as mine, that seemed to be the solution. However, the posting in BGDev had quite some problems, and the code was written on prima vista, so I had to do some modifications in order to have a good, working solution.

Here is the solution in details:

* Place the CCwatermark.php file in a directory, where it will be accessible by the web server and suits the best your needs;

* Configure the CCwatermark.php by editing the two macroses SMALL\_WATERMARK\_FILE and BIG\_WATERMARK\_FILE. You must put there the full path to your watermark images, since you do not know (at least I didn’t knew) what’s the current dir, from where your script will be executed;

* The script supports two watermark images at the moment: a “normal” one (named above as “BIG\_”), and a “small” one. The small one is used, if the width or height of the target picture is not at least 5 times bigger than the length of the “BIG\_” watermark. I had to do that, because otherwise the thumbnails of my images really sucked. If you do not wish to have two different watermark images, either modify the code, put two identical images, or give the same image name in the two macroses;

* Now you must put the following .htaccess file in each directory, which images you want to place watermark. If you already have .htaccess, you just add the following code to it:

AddHandler watermark .jpg
AddHandler watermark .jpeg
AddHandler watermark .gif
AddHandler watermark .png

Action watermark <the Apache-related path to your CCwatermark.php here>
Here is what these lines do to your web server:
* The first lines instruct your Apache web server to apply the action ‘watermark’ to all files of types .jpg, .jpeg, .gif and .png.
* The following line defines the ‘watermark’ action as forwarding the Apache to execute the given script. In my case, that was the ‘http://doncho.net/gal/CCwatermark.php’ script, it’s up to you to write the correct according to your own site, and how Apache serves it. Take special attention on the path, because it took me few hours to discover why I’m getting 404 Error, until I realized that the path is the URI and not direct path in my file structure.

* Please feel free to download the ZIP file with both .htaccess and CCwatermark.php.

__In case you decide to use this article or code for your own purposes, please have in mind that:__

* The author _does __not__ guarantee_ you that the code will not ruin out completely your whole site, causting you billions of USD loss. If you use the code, provided in this article, you agree that you have used anything from this article and code on your own behalf and you __release the original author from any potential loss__ (if you want, you can release the author from any potential profit too, but I will not deny you this choice :));
* Both __all the code__ and __this blog article__ are licensed under the Creative-CommonsAttribution license. This differs than the license of my blog, which is a bit more restrictive (and old).

One thought on “Watermark images for your gallery

Leave a Reply

Theme: Overlay by Kaira Extra Text