Convert words/files to images

Friday, September 28th, 2007 | geek

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 "< img xsrc="" mce_src=""       />”
(( 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!

5 Comments to Convert words/files to images

hesa
September 28, 2007

Hmm, the HTML formating in the script gets eaten up by wordpress.
Ask me for the sources in the unlikely case you want it

Jeremiah Foster
September 28, 2007

Um, this is not totally useless, rather this is quite useful. I am going to use the sources you printed on this site and try it out!

Jeremiah Foster
September 28, 2007

Is there no way to include the code you have written inside the tag? Then the Word Press mangling should be less evil. Though maybe not.

hesa
September 28, 2007

The problem is that I suck when it comes to HTML.

I’ll try to suck less in the future ;)

hesa
September 28, 2007

Added links to scripts outside wordpress ….. see original post :)

Leave a comment

You must be logged in to post a comment.

Search