
[Mr C Camacho] picked up an inexpensive digital picture frame hoping to hack into it. He hasn’t had the time to crack open the hardware so that it will do his bidding but he did find a creative way to make it an ebook reader. Using a python script he processes books, creating images of the pages.
The python script, available after the break, takes free books from Project Gutenburg and spits out JPG images. Page turning and bookmarking are not what they ought to be but the process does work. The thought of someone staring at a picture frame on the subway is a bit amusing but we’re sure that sooner or later someone will ask if it’s a new version of the Kindle.
Usage explanation from the developer:
./process.py book.txt 480 234 16 /usr/share/fonts/truetype/ttf-droid/DroidSansMono.ttf 10 7
param
1 * book.txt * * * the file name
2 * 480 * * * * * * *native X resolution of picture frame
3 * 234 * * * * * * *native Y resolution of picture frame
4 * 16 * * * * * * * *Number of vertical lines of text required
5 * blah.ttf * * * *full path and name of a ttf font
6 * 10 * * * * * * * *font size to use for lines
7 * 7 * * * * * * * * *font size for “page no x” at bottom of page
you’ll have to play with it to get it to work right for your size of screen
(its just a hack
)
The main thing to get right first is the font size of the width of the screen
from there you can work out the number of lines you can fit…
#!/usr/bin/pythonimport pygameimport sys# ./process.py book.txt 480 234 16 /usr/share/fonts/truetype/ttf-droid/DroidSansMono.ttf 10 7txtname=sys.argv[1]nativeX=int(sys.argv[2])nativeY=int(sys.argv[3])pagelines=int(sys.argv[4])fontname=sys.argv[5]fontsize=int(sys.argv[6])pagenosize=int(sys.argv[7])f=open(txtname)def cleanline(l): l=l.strip('\r') l=l.strip('\n') return lpygame.init()screen = pygame.display.set_mode((nativeX, nativeY))lines=f.readlines()font = pygame.font.Font(fontname, fontsize)pfont = pygame.font.Font(fontname, pagenosize)for ln in range(len(lines)/pagelines+1): background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((255, 255, 255)) for pl in range(16): if (ln*16+pl)param
1 * book.txt * * * the file name
2 * 480 * * * * * * *native X resolution of picture frame
3 * 234 * * * * * * *native Y resolution of picture frame
4 * 16 * * * * * * * *Number of vertical lines of text required
5 * blah.ttf * * * *full path and name of a ttf font
6 * 10 * * * * * * * *font size to use for lines
7 * 7 * * * * * * * * *font size for “page no x” at bottom of page
you’ll have to play with it to get it to work right for your size of screen
(its just a hack

The main thing to get right first is the font size of the width of the screen
from there you can work out the number of lines you can fit…