How can I turn a text file into a bunch of images using imagemagick?
June 17, 2014 6:50 PM   Subscribe

Say I have a text file with short lines of text (e.g. License plate numbers or radio call letters). I'd like to use imagemagick to convert this text file to a folder full of images of said text, with each line from the text file being a separate image. Preferably, I'd like the output to be named with the content. What are the magic command-line words to make this happen?

I'm on OSX Mavericks, and have managed to get imagemagick installed and working. I can generate a single test image from the command line.

Example: If a line of the file is "CU L8R", I'd like the image to be just those letters, and the filename to be CUL8R.png or similar.

Thanks, command line mavens!
posted by brentajones to Computers & Internet (4 answers total)
 
Your problem is underspecified (what resolution? what font? what colors? what line wrapping? what character spacing? etc., etc., etc.), but this might help.
posted by dmd at 7:19 PM on June 17, 2014


Response by poster: Sorry, I was unclear. I'm still fiddling with the exact font, colors, kerning etc. but I've been able to figure out the syntax for those ok. Assume I'm able to generate a single image from a single line of text with the specifications I want using the command line.

What I can't figure out are the proper commands for piping input from the text file, split by line, and then saving it out to multiple files.
posted by brentajones at 7:25 PM on June 17, 2014


Best answer: You can loop through the lines of a file in Bash like this:
while read line; do
  imagemagick --text "$line" --output "$line.png"
done <file.txt
That executes a separate ImageMagick command for each line (I made up the command, but you can put the variables into your working command).
posted by floomp at 7:44 PM on June 17, 2014 [2 favorites]


Response by poster: And that, along with some messing around with escape characters and such, did the trick. Thanks!
posted by brentajones at 8:37 PM on June 17, 2014


« Older Where to find casual men's clothes for the office?   |   Library books (and e-books) vs. physical copies of... Newer »
This thread is closed to new comments.