Convert words/files to images

Hi,

after a short discussion yesterday about safe registration and using images with text I decided it’s about time I learn how to create images from words on the command line. Or even better, generate a HTML file, made of images, from a GNU Xnee source file.

[Added after original post: scripts can be found here http://www.sandklef.com/stuff/bin/]

OK, here’s a file that takes a word as its first argument and a filename as second:

#!/bin/bash

export PRIMARY=”-size 800×120 xc:white ”
export TEXT_PRIMARY=”-fill black -annotate +20+80 ”
export TEXT_SHADOW=” -fill red -annotate +21+81 ”
export TEXT_SHADOW2=” -fill yellow -annotate +22+82 ”
ARG=$( echo “$1” | sed -e ‘s,\\\\*,*,g’)
#echo “gen for \”$1\” –> \”$ARG\””
convert $PRIMARY $TEXT_PRIMARY “$ARG” $TEXT_SHADOW “$ARG” $TEXT_SHADOW2 “$ARG” -trim
+repage $2

I named the file: word2png Here’s how to use it:

word2png “IFK” ifk.png

It’s about time for the next file. Read a text file (such as a header file in the Xnee sources), call word2png for every word in it, and add some HTML stuff. Here’s the file:

#!/bin/bash

TMP_DIR=/tmp/file2png
IDX_FILE=${TMP_DIR}/index.html

rm -fr ${TMP_DIR}
mkdir  ${TMP_DIR}
rm -f  ${IDX_FILE}
CNT=0

whtml()
{
echo "$*" >> ${IDX_FILE}
}

whtml "html body"
if [ "$1" = "" ] ; then echo "Missing file arg....." ; exit 1 ; fi
if [ ! -f $1 ] ; then echo "Missing file arg....." ; exit 1 ; fi

echo "Using file: $1"
while read line
do
#  echo "read $line"
ARG=$( echo "$line" | sed -e 's,*,*,g'  -e 's,,,g'  )
for i in $ARG
do
./word2png "$i" ${TMP_DIR}/${CNT}.png
whtml ""
(( CNT++ ))
done
whtml "
done <  $1

whtml "/body /html "

echo "wrote to: $IDX_FILE"

I called it: file2png Here’s how to use it:

file2png xnee.h

Then open up the file /tmp/file2png/index.html in your browser.

I know it’s useless….. but I really think it’s kind of fun!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s