In my last post I showed how you can add your own custom functions to the GNOME file manager with Nautilus Actions. I've also shown previously how to batch watermark images with ImageMagick. I've made some adjustments to my previous script so that it will automatically scale the watermark to fit the target image. This new version will also deal with spaces in the file names.
Here's the new script. Save it as auto_wm somewhere within your $PATH. I have mine saved in /home/linerd/bin/.
#!/bin/bash ########################################### # NAME: auto_wm # AUTHOR: Linerd (https://tuxtweaks.com), Copyright 2009 # LICENSE: Creative Commons Attribution - Share Alike 3.0 http://creativecommons.org/licenses/by-sa/3.0/ # You are free to use and/or modify this script. If you choose to distribute this script, with or # without changes, you must attribute credit to the author listed above. # REQUIRES: ImageMagick, coreutils # VERSION: 1.0 # DESCRIPTION: A script to add a watermark to selected images. This script will automatically scale your # watermark to fit the selected image. The watermarked image will be saved as filename_wm.*, # leaving your original image untouched. # USAGE: Place your watermark image in ~/Documents/Watermark.png or change the path in line 22. # Can be run from the terminal with: auto_wm image_list # This script will also work with Nautilus Actions in GNOME and Dolphin Actions in KDE. # # ########################################### # Initialize variables WM=$HOME/Documents/Watermark.png # This is the path to your watermark image WMW=`identify "$WM" | awk -F' ' '{ print $3 }' | awk -F 'x' '{ print $1 }'` # Watermark Width WMH=`identify "$WM" | awk -F' ' '{ print $3 }' | awk -F 'x' '{ print $2 }'` # Watermark Height # Set the field separator SAVEIFS=$IFS IFS=$(echo -en "\n\b") # Process images for i in $@ do IMAGE=$i IMAGEW=`identify -verbose "$IMAGE" | grep Geo | awk -F': ' '{ print $2 }' | cut -d'+' -f1 | cut -d'x' -f1` # Image Width IMAGEH=`identify -verbose "$IMAGE" | grep Geo | awk -F': ' '{ print $2 }' | cut -d'+' -f1 | cut -d'x' -f2` # Image Height SCALEW=`echo "scale=2; $IMAGEW / $WMW * 90" | bc | awk -F'.' '{ print $1 }'` # echo $SCALEW $IMAGEW $WMW SCALEH=`echo "scale=2; $IMAGEH / $WMH * 90" | bc | awk -F'.' '{ print $1 }'` # Set the scale for the watermark if [ $SCALEW -le $SCALEH ]; then SCALE=$SCALEW else SCALE=$SCALEH fi # Watermark the image NAME=`echo $IMAGE | cut -f1 -d.` EXT=`echo $IMAGE | cut -f2 -d.` composite -dissolve 40% -gravity center -quality 100 \( $WM -resize $SCALE% \) "$IMAGE" "${NAME}_wm.${EXT}" done # Reset the field separator IFS=$SAVEIFS exit 0
Make sure to make the script executable with
Now open the Nautilus Actions Configuration tool with
Create a new action called Watermark. Under the Main profile, set the Path to /home/linerd/bin/auto_wm (make the appropriate adjustment for your path). Set the Parameters to %M. On the Conditions tab set the Mimetypes to image/*. Also make sure to check the box for multiple file selection.
Close out the Nautilus Actions Configuration tool and quit Nautilus with
Restart Nautilus with
Your new Watermark action will now show up when you right click on image files in Nautilus.
Note: The watermark image you want to use should be stored in /home/yourid/Documents/Watermark.png. If your image is stored somewhere else, make the appropriate changes to the script.
#