How To Watermark Images With ImageMagick in Linux
I recently discovered that one of my most popular posts had been poached by another blog with out providing credit - images and all. I decided that it would be best to watermark my images to make it more difficult to rip off my content.
This procedure could also be done easily in GIMP, but it takes time to open up each image and then import or create the watermark text. Instead I created my desired watermark text in GIMP and saved it as a separate file called Watermark.png. This file has a transparent background, so only the text will show up when it's overlaid on another image.
For my demo I'm going to overlay the watermark on an image of Tux, the Linux mascot.
To create the watermark I'm going to use the composite command from the ImageMagick package. The structure of my command assumes that both the watermark and target images are in the same directory.
composite -dissolve 50% -gravity center -quality 100 Watermark.png Tux.jpg Tuxwm.jpg
This creates a new image called Tuxwm.jpg.
A little explanation of the command we performed. composite is the command to combine two images. The dissolve 50% switch tells ImageMagick to make the overlay image 50% transparent. The gravity center switch tells it to center the overlay image on the base image.
As you can see above, my watermark image is too large compared to the image of Tux. I'll need to shrink it in order for the result to look how I want. Now, I could go into GIMP and resize my watermark image, but ImageMagick provides an easy way to do this on the fly. With a slight modification to the above command I can scale down the watermark before it's overlaid.
composite -dissolve 50% -gravity center -quality 100 \( Watermark.png -resize 50% \) Tux.jpg Tuxwm.jpg
That looks a little bit better. Note that these commands have created a new image called Tuxwm.jpg. You can make the command overwrite the original image if you just pass the same file name at the end of the command like this.
composite -dissolve 50% -gravity center -quality 100 \( Watermark.png -resize 50% \) Tux.jpg Tux.jpg
This may seem a bit complicated to type this command to watermark a single image, but the nice thing is that it can be automated in a script so that you can watermark a whole directory of images at the same time. You can see that post here.