I am using the convert command to annotate images with text:

convert -pointsize 20 -fill green -draw 'text 270,460 "[TEXT TO ANNOTATE]" ' [INPUT IMAGE NAME].jpg [OUTPUT IMAGE NAME].jpg

I have 100 images and a single .txt file of 100 unique words with each word on their own line. How can I make it so that every single one of the 100 images gets annotated with the text from a single line of the .txt file? To clarify, I want them to be unique - there shouldn't be more than one image annotated with the same text. I'm new to shell scripting and don't even know where to start.

  • The design is no robust, add a stray file and the words won't end up on the right images. It would be quite easy to have a file where lines contain both a file name and the word to apply to the image.
    – xenoid
    Jul 25, 2020 at 7:58

1 Answer 1


If I understand the request correctly, that could be (POSIX sh syntax):

for file in ./*.[jJ][pP][gG]; do
  IFS= read -r text <&3 || break
  convert -pointsize 20 \
          -fill green \
          -draw "text 270,460 \"$text\"" \
          "$file" "${file%.*}-annotated.${file##*.}"
done 3< /path/to/list.txt

(assuming there's no double quotes in the lines of list.txt).

That processes all the .jpg (case insensitively) files in the current directory in alphabetical order, and for each, one line of text is read from list.txt, the jpg is annotate with the text in that line and saved as original-annotated.jpg.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .