I need to write a bash script that would annotate a given image using imagemagick. The problem is, that image could be any size and its annotation should look nearly same on any image.
Output result should look like this on any image:
So there are some points I'd like to figure out:
Using ImageMagick version 6 or 7 you can make a label sized to fit any input image, with a semi-transparent background, and composite it at the bottom of the input image to get the result you describe. Here is a command with IM 6 that does it...
convert input.png -set option:size %[w]x \
-fill white -background "#00000080" \
\( label:"This is my text." \
-virtual-pixel background -distort SRT "0.8 0" \
-virtual-pixel none -distort SRT "0.8 0" \) \
-gravity south -composite result.png
That uses the width of the input image "%[w]" to set the width of the label. It sets the text color to white and the background to semi-transparent black, "#00000080".
Inside the parentheses it creates your label. It uses "distort SRT" to scale the label down a bit to pull it in from the edges. Then it scales the label down a bit more to add some transparent space around it.
After the label is created it sets the gravity to "south" and composites the label onto the input image. It finishes by writing the output file.
Using IM 7 you'll need to change "convert" to "magick". For Windows change the continued line backslashes "\" to carets "^" and get rid of the backslashes that escape the parentheses.
Edited to add: Normally you'd use "-size WxH" ahead of making a "label:" to constrain it within particular dimensions. I used "-set option:size" instead because it allows for using percent escapes like "%[w]" with IM 6. That way the label dimensions are relative to any input image width.