Example #1
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()
        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
Example #3
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')
Example #4
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')
Example #5
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
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
Example #7
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
Example #8
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')
Example #9
0
 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
Example #10
0
    shutil.copytree(source, dest)

### Custom Pages    
FILENAME = 'attendees1.csv'
people = list(csv.reader(open(FILENAME)))
header = people[0]
people = people[1:]

if os.path.exists(CUSTOM_DIR):
    shutil.rmtree(CUSTOM_DIR)
os.mkdir(CUSTOM_DIR)

for person in people[:]:
    person = Attendee(person, header)
    print person.name, person.headshot, person.logo
    pages = [WIF() for i in range(N_PAGE)]
    
    qr = person.qr().resize((QR_SIZE, QR_SIZE))
    for page in pages:
        page.addImage(Image.open(os.path.join(BACKGROUND)), 0, 0)
    pages[0].addImage(Image.open(os.path.join(HEADSHOT_DIR, person.getHeadshot())), 112, 0)
    pages[1].addImage(qr, WIDTH - QR_SIZE, 0)
    pages[2].addImage(Image.open(os.path.join(LOGO_DIR,  person.getLogo())), 112, 0)
    for page in pages:
        for i, role in enumerate(person.roles):
            page.addUnifont(role[:14], 0, 0 + (i + 1) * 16 + 5, bigascii=False)
            # page.addUnifont(role, 0, 0 + i * 16 + 5, bigascii=False)
            # page.addText(role, 0, 10 + i * (NORMAL_FONT_SIZE + 5) + 5)
        page.addText(person.name, WIDTH/2, HEIGHT, font_size=NAME_FONT_SIZE, halign='center', valign='bottom')

    dir = CUSTOM_DIR + '%04d-%s/ALBUM/' % (int(person.id), '_'.join(person.name.split()))
Example #11
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
Example #12
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