ImageMagick is an awesome image manipulation tool. It provides an command-line API for literally hundreds of functionalities related to image editing. Every now and then I need to apply watermarks to my images before posting them somewhere online, in public. GIMP, has one or two scripts which extend its functionalities but there’s no neat way to make them work nor use. So I decided to research a bit more about ImageMagick compose and create a very simple bash script to convert my images whenever I want.
To keep the alpha channel (transparency) of your watermarks you should use .png
images or .svg
. In my case, .svg
didn’t work as expected but I exported it as .png
. To breakdown the parts of the composite command see the section below; If you just want to get it done skip the next section.
To change the position of your watermark modify -gravity
with the available options NorthWest
, North
, NorthEast
, West
, Center
, East
, SouthWest
, South
, SouthEast
You can find more scripts in my github repo here
The script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#! /bin/bash # Syntax: watermark-images.sh /path/to/dir /path/to/dir /path/to/logo.png extention sourcedir="$1" targetdir="$2" watermark="$3" ext="$4" imgs=$(find "$sourcedir" -name *.$ext -print) SAVEIFS=$IFS IFS=$(echo -en "\n\b") if [ ! -d "$targetdir" ]; then mkdir "$targetdir" fi for i in $imgs; do composite -compose atop -gravity southeast -background none "$watermark" "$i" "$targetdir/$(basename $i)" done IFS=$SAVEIFS |
Thanks for your great article, I’m using VeryUtils Photo Watermark Command Line software, it support command line processing, I could use it to batch add watermarks to all of my photos at one time, I’m happy with it.
Thanks bro, are you best!!