Skip to content

Instantly share code, notes, and snippets.

@Birchwell
Created October 16, 2015 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Birchwell/4c675025e91d0c70b129 to your computer and use it in GitHub Desktop.
Save Birchwell/4c675025e91d0c70b129 to your computer and use it in GitHub Desktop.
This Thunar Custom Action will create a watermark on an image, with customized text from a YAD entry form.
#!/bin/sh
command -v convert >/dev/null 2>&1 || { echo >&2 "I require convert, but it's not installed. aborting!";exit 1;}
command -v identify >/dev/null 2>&1 || { echo >&2 "I require identify, but it's not installed. aborting!";exit 1;}
command -v bc >/dev/null 2>&1 || { echo >&2 "I require bc, but it's not installed. aborting!";exit 1;}
basedir="$(dirname "$(readlink -f "${1}")")"
cd "$basedir"
caption=$(yad --entry --editable --no-buttons --width 410 \
--title="Please enter your caption and press enter:")
if [ -z "$caption" ]; then
printf "no caption was selected, aborting!\n"
exit 1
fi
printf "caption is $caption\n"
if [ ! -d "$basedir"/backups ]; then
mkdir -p "$basedir"/backups
fi
while [ $# -gt 0 ]; do
file="$1"
if [ -s "$file" ]; then
cp -f "$file" backups
export imagesize=$(identify -format "%w,%h" "$file")
export imagewidth=$(echo "$imagesize" | cut -f1 -d',')
export imageheight=$(echo "$(echo "$imagesize" | cut -f2 -d',')*0.06000" | bc)
convert -background '#0008' -fill white -gravity center \
-size $(echo $imagewidth)x$(echo $imageheight) caption:"$caption" \
"$file" +swap -gravity south -composite "$file" && \
printf "\n$file watermarked successfully\n"
fi
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment