def create_sched(filename): dat = open(filename).readlines() x = 0 y = 0 page = WIF() page_no = 0 for line in dat: line = line.strip() def closewif(page, page_no): page.im.save(SCHEDULE_DIR + chr(ord('A') + page_no) + '.png') page_no += 1 page = WIF() return page, page_no, 0 if line.startswith('<P>'): ## new page line = line[3:] if y > 0: page, page_no, y = closewif(page, page_no) if line.startswith('<B>'): line = line[3:] bigascii = True wrap = 44 else: bigascii = False wrap = 44 for l in textwrap.wrap(line, wrap, subsequent_indent=' '): # page.addUnifont(l, x, y, bigascii=bigascii) page.add_7x5_txt(l, x, y) y += 9 if y > 176 - 9: page, page_no, y = closewif(page, page_no) closewif(page, page_no)
def create_sched(filename): dat = open(filename).readlines() x = 0 y = 0 page = WIF() page_no = 0 for line in dat: line = line.strip() if line.startswith('<B>'): line = line[3:] bigascii = True wrap = 44 else: bigascii = False wrap = 44 for l in textwrap.wrap(line, wrap, subsequent_indent=' '): # page.addUnifont(l, x, y, bigascii=bigascii) page.add_7x5_txt(l, x, y) y += 9 if y > 176 - 16: if not os.path.exists(SCHEDULE_DIR): os.mkdir(SCHEDULE_DIR) page.im.save(SCHEDULE_DIR + chr(ord('A') + page_no) + '.png') # page.saveas(dir + chr(ord('A') + no) + '.WIF') page_no += 1 if page_no % 100 == 0: print 'page:', page_no page = WIF() y = 9
def create_ebook(filename, top_dir): wrap = 44 if not os.path.exists(top_dir): os.mkdir(top_dir) dat = open(filename).readlines() x = 0 y = 3 page = WIF() chapter_no = 0 page_no = 0 dir = os.path.join(top_dir, ('%04d' % chapter_no + '/')) for line in dat: if line.startswith('<CHAPTER'): ### finish off current chapter ... if not os.path.exists(dir): os.mkdir(dir) fn = dir + ('%04d' % page_no) + '.png' page.im.save(fn) page.saveas(fn[:-3] + 'WIF') # ... and get ready for next chapter_no += 1 dir = os.path.join(top_dir, ('%04d' % chapter_no + '/')) print dir page_no = 0 page = WIF() continue for l in textwrap.wrap(line, wrap, subsequent_indent=''): page.add_7x5_txt(l, x, y) y += 9 if y > 176 - 9: if not os.path.exists(dir): os.mkdir(dir) fn = dir + ('%04d' % page_no) + '.png' page.im.save(fn) page.saveas(fn[:-3] + 'WIF') page_no += 1 page = WIF() y = 0
def create_sched(filename): dat = open(filename).readlines() x = 0 y = 0 page = WIF() page_no = 0 for line in dat: line = line.strip() if line.startswith('<B>'): line = line[3:] bigascii = True wrap = 44 else: bigascii = False wrap = 44 for l in textwrap.wrap(line, wrap, subsequent_indent=' '): page.add_7x5_txt(l, x, y) y += 9 if y > 176 - 16: page.im.save(SCHEDULE_DIR + chr(ord('A') + page_no) + '.png') page_no += 1 page = WIF() y = 9
#!/usr/bin/env python import textwrap import unifont import shutil import os.path import glob from PIL import Image from PIL import ImageFont from PIL import ImageDraw import qrcode import csv from wif import towif, WIF, PAGE, NAME_FONT_SIZE, NORMAL_FONT_SIZE, WIDTH, HEIGHT dat = open('page02.txt').readlines() x = 0 y = 0 page = WIF() for line in dat: wrap = 44 for l in textwrap.wrap(line, wrap, subsequent_indent=' '): page.add_7x5_txt(l, x, y) y += 9 page.saveas('PAGE02.WIF')