Exemple #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')
Exemple #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')
Exemple #3
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
Exemple #4
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