I'm looking for a program that is able to output an image with my inputted text on it. Sort of like a template, I would input varying text / numbers and an image, and the program will output the image with the text on top of it in my specified coordinates. I'd like to do it in bulk. What's the best program I could use for this?
2 Answers
The convert command from ImageMagick can do what you want, letting you specify the font size, colour, and where the place the text.
eg
convert -pointsize 20 -fill yellow -draw 'text 270,460 "My string" ' source.jpg results.jpg
ImageMagick's convert is the old eminence in that field. Personally, I find it terrible, both in a lot of aspects of the CLI as well as in speed. (That doesn't have to stop you.) It might also be one of the most often exploited pieces of software running on web servers.
GraphicsMagick's gm is in my humble opinion much nicer and can do things like:
#!/usr/bin/zsh
export text="Liam likes birds"
for infile in bird*.jpg; do
gm convert \
-font helvetica \
-pointsize 48 \
-fill blue \
-draw "text 100,100 \"${text}\""
${infile} ${infile:r}-with-text.webp
done
(you'll notice how GraphicsMagick is clearly a fork of ImageMagick. Or rather, both software fell from the same tree, and I'd argue GraphicsMagick landed a bit less precariously ;-P. Though it's been less commonly exploited than ImageMagick, you might want to consider the risk of running software on images that your users can send you, if that's your use case. It's also been much less widely deployed, so it was a bit less of an attractive object of exploitation.)
If your problem is more complicated, there's other ways, such as using an SVG file "template" with an image file referenced inside, which your scripting could replace, then render to an image using e.g. rsvg-convert.