How To Watermark Images With ImageMagick in Linux

August 14, 2009 by
Filed under: command line, HowTo, linux, web development 

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.

Watermark

For my demo I'm going to overlay the watermark on an image of Tux, the Linux mascot.

Affiliate Link

Tux, the Linux penguin

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.

Tux watermarked

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
Tux re-watermarked

Tux re-watermarked

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.

Comments

10 Responses to “How To Watermark Images With ImageMagick in Linux”

  1. dashaman says:

    hi, is there any syntax available for -gravity aside from center? thanks in advance

  2. repettus says:

    Dont know why but its working now, never mind

  3. repettus says:

    Unfortunately this does not work for me. In Ubuntu 9.1, I tried composite -gravity center image1.png image2.gif outputimage.jpg. However, I get " unable to open image `temp.png': No such file or directory @ blob.c/OpenBlob/2439.

  4. Linerd says:

    I discovered an issue with watermarking TIFF images. I have added the -quality 100 switch to address this.

  5. iggykoopa says:

    here's a script I wrote to do something similar for a #! forum member http://crunchbanglinux.org/forums/topic/3738/image-resizerwatermarker/ . Good tutorial ;)

    • Linerd says:

      iggykoopa - Thanks for the link. I'm working on a similar script. It's always interesting to see how someone else goes about doing things. I've been playing around with Zenity, but haven't really done much with it yet. Something I struggle with is deciding how much to hard code into the script vs. presenting options to the user. For myself, I like things hard coded in since it makes things quicker for me when I run the script, but I know that is not the most desirable way for many users.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>