I'd like the script to be converted into a one-line command, if possible. I've included some example images below. If I'm not able to get it to work with WSL, then perhaps I'll install ImageMagick on Windows, but I'd prefer to use it with WSL.
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"
echo "Please enter your caption and press enter"
read caption
if [ -z "$caption" ]; then
printf "no caption was selected, aborting!\n"
exit 1
fi
printf "caption is $caption\n"
if [ ! -d "$basedir"/bakups ]; then
mkdir -p "$basedir"/bakups
fi
while [ $# -gt 0 ]; do
file="$1"
if [ -s "$file" ]; then
cp -f "$file" bakups
export imagesize=$(identify -format "%w,%h" "$file")
export imagewidth=$(echo "$imagesize" | cut -f1 -d",")
export imageheight=$(echo "$(echo "$imagesize" | cut -f2 -d",")*0.03000" | 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