Example #1
0
 def layout_text(self):
     '''
     Put the text on the image.  Does not resize image1
     '''
     if self.unifont_f:
         unifont.addText(self.text, self.image1, 0, 0, self.bigascii)
     else: ## default to 5x7 font
         ascii_5x7.addText(self.text, self.image1, 0, 0)
Example #2
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 #3
0
 def addUnifont(self, txt, x, y, **kw):
     unifont.addText(txt, self.wff_file, self.im, x, y, **kw)
Example #4
0
 def addUnifont(self, txt, x, y, **kw):
     unifont.addText(txt, self.im, x, y, wff_file=self.wff_file, **kw)
Example #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