I know that most of my posts lately have been on photography and have been leaving the tech side behind quite a lot…so this is back on to bash scripting
Most people who post photos online have some sort of watermarking so that their images aren’t easily stolen. Some watermarks are annoying and simply ruin the whole image because they’re intrusive and all over the image so to those people all I have to say is why post them on the internet?
There are other watermarks that aren’t intrusive and are either artistic or minimalistic. I’m currently using a minimalistic watermark which basically is just a black line on the bottom of the image with my name, year and blog url. But how exactly do we add the watermark onto the images? Well there are multiple ways to do so and I’m pretty sure that there are programs that will do it for you automagically but I’ll talk about my method so you can choose whether it’s the best or not
I wrote a bash script that will recieve the images via parameter and will watermark those images after resizing them to a certain size that has been established. The script calls the identify, convert and composite tools from the ImageMagik toolset in order to determine the size of the image, resize the image and to add the watermark.
The script has several variables which contain the information necessary to do the resize and the watermarking and they are:
- WATERMARK=”/home/lmurillo/Documents/photography/photomark.jpg”
- ISIZE=”1024″
- WLOCATION=”southwest”
- WTRANSPARENCY=”65″
The WATERMARK variable is the location of the watermark and can be any image file supported by the ImageMagik toolset but I’ve choosen to use a JPEG file. The dimensions of this image is 1024×12 which means that the watermark fits nicely on any image that has a width of 1024 pixels or less so if I were to add the watermark to an image bigger than 1024 pixels in width you would see a black line that doesn’t cover the whole bottom width of the image which is not good in this case.
The ISIZE variable is the pixels to which the image will be resized on it’s longest side. In this case the image will always be 1024 on it’s longest side or at least it should be ;). I don’t only take horizontal images so I had to fix the original script so that it detects whether the image is vertical or horizontal and resize the image on the longest side accordingly.
The WLOCATION variable is the location in which the watermark will be applied and it takes the same parameters that the composite tool takes for the gravity option, which means that it’s the cardinal points (if that’s how they’re really called), for example south, north, southwest…so on and so forth.
The WTRANSPARENCY variable is the level of transparency that the watermark will be applied with. The lower the number the more transparent it’ll be. I’ve found that at 65 is good enough for all of my images.
The script goes on to check to see whether there are images specified or not and exits if there aren’t any. If there are any images then it enters a loop which will determine which images are bigger than 1024 pixels so that it resizes the images and adds the mark since I consider that the images that are 1024 pixels or smaller either have the watermark already or are simply not fit for the watermark. At first I didn’t add this check and it turns out that if the image is smaller than that it will actually strech it to that so the image is pixelated so it wasn’t useful. To be on the safe side anything smaller or equal to the size that I have established on the ISIZE variable won’t be watermarked but I need to find a way to force the watermarking which is most likely going to be something like adding an option that can be passed at run time.
If you want to download the script or take a look at it you can do so by going to:
http://files.codebeta.net/addmark
You can change the value of the variables to change the size that the images will end up with and other information. The watermark can be of any size you want. I use this script to apply the watermark in a batch of photos though I’m looking into the possibility of creating a more artistic signature that can be added though I’m wondering about the transparent background so that it’s not a box in the image.
-LM












Long time, no write…
Well, there have been numerous gaps between the posts and I apologize for this, since I have been quite busy lately. Let’s see, for starters I’m training a new group of agents for my department where I work and my family is planning a trip to Taiwan to visit my sister.
Continue reading ‘Long time, no write…’