[TAG] 2-cent tip: Converting text to an image

Bradley Chapman kakadu at gmail.com
Sun Mar 6 14:08:35 MSK 2005


Mr. Okopnik,

On Sun, 6 Mar 2005 01:09:00 -0500, Ben Okopnik <ben at linuxgazette.net> wrote:
> Once in a while, I need to convert a text file to an image. Whether
> changing an email address to a pic in order to foil spammers or flipping
> an article to pictorial form for editorial markup (my fiancee is also an
> editor... a marriage between two editors boggles the mind and is
> probably illegal in many jurisdictions!), I've found the process
> somewhat abstruse and the relevant information curiously sparse and
> difficult to find. So, for those who may run into the same requirements
> - not necessarily an editorial combinatorial :) but text-to-image
> conversions - here is the script that I use. Despite its seeming
> simplicity, it's taken a good bit of searching to get it to its present
> state: it started life as a couple of dozen lines of code and was
> gradually reduced to what it is now. I hope you find the results useful!
> 
> ``
> #!/bin/bash
> # "text2img" Created by Ben Okopnik on Fri Mar  4 13:50:21 EST 2005
> 
> [ -f "$1" ] || { printf "Usage: ${0##*/} <textfile> [image_type]\n"; exit; }
> 
> convert text:"$1" "${1%.*}%d.${2:-jpg}"
> ''
> 
> If invoked as
> 
> ``
> text2img foo.txt
> ''
> 
> it will produce one or more JPGs of the text file - one image for each
> page. If, however, you prefer a different image format - say, PNG - the
> invocation becomes slightly different:
> 
> ``
> text2img foo.txt png
> ''
> 
> For more information (as well as the available image types), see "man
> ImageMagick".

Neato. Thanks for the tip; I may end up using this on my website for
e-mail addresses.

Brad




More information about the TAG mailing list