I want to be able to overlay text in the margin of images with varying dimensions. Images of varying dimensions will have a black margin that is 30% the width of the image.
I have the following bash script:
#!/bin/bash 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.05" | bc) convert -background "#0008" -font /usr/share/fonts/truetype/fonts-georgewilliams/CaslonRoman.ttf -pointsize 80 -fill white -gravity east \ -size $(echo $imagewidth)x$(echo $imageheight) caption:"$caption" \ "$file" +swap -gravity east -composite "$file" && \ printf "\n$file watermarked successfully\n" fi shift done
It gives me this result:
The text extends past the black margin.
I want the text to stay within the margin, and I want removed that shaded horizontal bar behind the text.
I could tweak the bash script and change the pointsize so that the text stays within the margin, but I want this accomplished automatically without my having to tweak the bash script for images of varying dimensions.
I want the text/margin placement to look like this example below: