Batch create images from text file with Irfanview?

3.1k Views Asked by At

I have a file of several thousand text strings with an associated ID number. I want to take each distinct text string and make it a JPG image of the text, and have the file named with the associated ID number.

All of the strings are a maximum of 75 characters, so I don't need to worry about dynamic sizing of the image to compensate for longer strings. I'd just like to set a single image size.

I use Irfanview for most of my batch imaging needs, and given its flexibility I assume that there's a way to do this. Does anyone know how this can be done?

1

There are 1 best solutions below

3
On BEST ANSWER

I don't believe that is possible with Irfanview - though I have not used that program much. There is a list here of the commandline options to Irfanview, and there is no mention I can see of label, text or annotate.

I can only suggest ImageMagick, which is free and available for Linux, OSX and Windows.

If your input file is called IdAndText.txt and looks like this:

id123456:Some text
id987654:Some different text, and a comma
id111222:Yet more stuff

then you could run something like this

#!/bin/bash
while IFS=":" read id text; do
   convert -size 1000x250 xc:black -fill yellow -pointsize 36 -gravity center -draw "text 0,0 '$text'" $id.png
done < IdAndText.txt

and you'll get this

id123456.png

enter image description here

id987654.png enter image description here

id111222.png

enter image description here

There is a mad Windows-y way of reading the text file, that I may experiment with and report back, but the ImageMagick part is more-or-less the same in Windows.

In Windows it is something like:

FOR /F "delims=: tokens=1,*" %%A IN (IdAndText.txt) DO convert -size 1000x250 xc:black -fill yellow -pointsize 36 -gravity center -draw "text 0,0 '%%B'" %%A.png