Code: Select all
#!/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 '#000000' -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