Esempio n. 1
0
def wif_directory(dir, level, rotate=False):
    files = glob.glob(os.path.join(dir, '[A-Z].png'))
    files.sort()
    for i, img_fn in enumerate(files):
        page = WIF()
        fn = os.path.split(img_fn)[1]
        page.addImage(Image.open(img_fn), 0, 0)
        page.addBreadCrumb(0, 0, level, i, BREADCRUMB_SHAPE)
        if rotate:
            page.rotate180()
        page.saveas(OUTPUT_DIR + chr(ord('A') + level) + '/' + fn[0] + '.WIF')
Esempio n. 2
0
def wif_directory(dir, level, rotate=False):
    files = glob.glob(os.path.join(dir, '[A-Z].png'))
    files.sort()
    for i, img_fn in enumerate(files):
        page = WIF()
        fn = os.path.split(img_fn)[1]
        page.addImage(Image.open(img_fn), 0, 0)
        page.addBreadCrumb(0, 0, level, i, BREADCRUMB_SHAPE)
        if rotate:
            page.rotate180()
        page.saveas(OUTPUT_DIR + chr(ord('A') + level) + '/' + fn[0] + '.WIF')
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
Esempio n. 4
0
#!/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')
Esempio n. 5
0
def create_frontpage(sd,
                     alb='ALBUM/A',
                     filename=None,
                     headshot=None,
                     headshot_bbox=None):
    assert os.path.exists(sd)
    photo_only = False

    frontpage = WIF()

    if headshot is None or not os.path.exists(headshot):
        headshot = 'DEFAULT_HEADSHOT.png'
    ### Custom Page
    dir = os.path.join(sd, alb)
    image_dir = os.path.join(dir, 'A')

    if not os.path.exists(dir):
        print "%s not present" % alb
        dir = '.'
    if filename is None:
        photo_only = True
    else:
        filename = os.path.join(dir, 'A', filename)
        if not os.path.exists(filename):
            photo_only = True
            print "Cannot find personal record:", filename
    if headshot:
        print 'adding headshot "%s"' % headshot
        head = Image.open(headshot)
        print "head.size", head.size
        if headshot_bbox is None:
            if photo_only:
                headshot_bbox = ((WIDTH - head.size[0]) / 2,
                                 (HEIGHT - head.size[1]) / 2,
                                 (WIDTH + head.size[0]) / 2,
                                 (HEIGHT + head.size[1]) / 2)
            else:
                headshot_bbox = (112, 0, 264, 128)

        frontpage.addImage(head, headshot_bbox[0], headshot_bbox[1])
    if not photo_only:
        person = list(csv.reader(open(filename)))
        header = person[0]
        person = person[1]

        person = Attendee(person, header)
        print person.name
        ohs2013 = Image.open('ohs2013_thumb.jpg')
        frontpage.addImage(ohs2013, 5, 5)

        for i, role in enumerate(person.roles):
            frontpage.addUnifont(role, 5, 5 + (i + 1) * 16, bigascii=False)
        size = unifont.calcsize(person.name, bigascii=True)
        NAME_AREA = NAME_W, NAME_H
        scale = int(
            min([NAME_AREA[0] / float(size[0]),
                 NAME_AREA[1] / float(size[1])]))
        image1 = Image.new('L', size, WHITE)
        size = size[0] * scale, size[1] * scale
        unifont.addText(person.name, image1, 0, 0, bigascii=True)
        image2 = image1.resize(size)

        frontpage.im.paste(image2, ((NAME_W - size[0]) / 2, 176 - 24), 0)
        frontpage.addBreadCrumb(0, 0, 0, 0, BREADCRUMB_SHAPE)
    frontpage.saveas(os.path.join(image_dir, 'A.WIF'))
    # frontpage.show()
    return frontpage
Esempio n. 6
0
def create_frontpage(sd, alb='ALBUM/A', filename=None, headshot=None, 
                     headshot_bbox=None):
    assert os.path.exists(sd)
    photo_only = False

    frontpage = WIF()

    if headshot is None or not os.path.exists(headshot):
        headshot = 'DEFAULT_HEADSHOT.png'
    ### Custom Page    
    dir = os.path.join(sd, alb)
    image_dir = os.path.join(dir, 'A')

    if not os.path.exists(dir):
        print "%s not present" % alb
        dir = '.'
    if filename is None:
        photo_only = True
    else:
        filename = os.path.join(dir, 'A', filename)
        if not os.path.exists(filename):
            photo_only = True
            print "Cannot find personal record:", filename
    if headshot:
        print 'adding headshot "%s"' % headshot
        head = Image.open(headshot)
        print "head.size", head.size
        if headshot_bbox is None:
            if photo_only:
                headshot_bbox = ((WIDTH - head.size[0])/2,
                                 (HEIGHT - head.size[1])/2, 
                                 (WIDTH + head.size[0])/2,
                                 (HEIGHT + head.size[1])/2
                                 )
            else:
                headshot_bbox = (112, 0, 264, 128)

        frontpage.addImage(head, 
                           headshot_bbox[0], headshot_bbox[1])
    if not photo_only:
        person = list(csv.reader(open(filename)))
        header = person[0]
        person = person[1]

        person = Attendee(person, header)
        print person.name
        ohs2013 = Image.open('ohs2013_thumb.jpg')
        frontpage.addImage(ohs2013, 5, 5)

        for i, role in enumerate(person.roles):
            frontpage.addUnifont(role, 5, 5 + (i + 1) * 16, bigascii=False)
        size = unifont.calcsize(person.name, bigascii=True)
        NAME_AREA = NAME_W, NAME_H
        scale = int(min([NAME_AREA[0] / float(size[0]), NAME_AREA[1] / float(size[1])]))
        image1 = Image.new('L', size, WHITE)
        size = size[0] * scale, size[1] * scale
        unifont.addText(person.name, image1, 0, 0, bigascii=True)
        image2 = image1.resize(size)

        frontpage.im.paste(image2, ((NAME_W - size[0]) / 2, 176 - 24 ), 0)
        frontpage.addBreadCrumb(0, 0, 0, 0, BREADCRUMB_SHAPE)
    frontpage.saveas(os.path.join(image_dir, 'A.WIF'))
    # frontpage.show()
    return frontpage