1

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?

  • I presume you are on Windows? How does your input file look - maybe show a few lines. Any willingness to use ImageMagick and/or Linux? – Mark Setchell Apr 09 '15 at 08:23

1 Answers1

6

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Mark, thank you very much for the solution, I will try it as I have a need to do this many times. I found a (less efficient) way to do it. – SagaciousCetacean Apr 10 '15 at 23:15
  • Mark, thank you very much for the solution, I will try it. I've done some previous work with imagemagick but not too much. I found a (less efficient) way to do it using irfanview. It actually has a text overlay feature utilizing the filename. I experimented and found the perfect size picture to use it with (400x200 for max 80 characters). Then I used CMD to duplicate 826 copies of that file. I then created a batch script to rename each of those files with each line of text that I needed. Then I ran Irfanview to make the images, and another batch script to rename with the appropriate ID. – SagaciousCetacean Apr 10 '15 at 23:20
  • Glad you have got it sorted. Please consider either accepting my answer (by clicking the hollow green tick/checkmak beside the vote counts), or writing up and posting your own answer and accepting that so that other users don't think the question is unanswered and they can see a method that works. Good luck. – Mark Setchell Apr 11 '15 at 09:29