Exemple #1
0
def promissoryCard(color, title, body, titlesize, fontsize):
    filename = 'Promissory_' + color + '.jpg'
    img = getImage(filename)
    draw = ImageDraw.Draw(img)

    # TITLE
    font = FontData('HandelGothicDBold.otf', 39 + titlesize,
                    (255, 255, 255, 255))
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(30, 20, CARD_W - 30, 100)
    textBlock.setLineHeight(39 + titlesize)
    textBlock.setCenterV(True)
    textBlock.setText(title)
    textBlock.draw(draw)

    # BODY
    font = FontData('MyriadProRegular.ttf', 31 + fontsize, (0, 0, 0, 255))
    boldFont = FontData('MyriadProBold.ttf', 31 + fontsize, (0, 0, 0, 255))
    overrideFont = FontData('HandelGothicDBold.otf', 24 + fontsize,
                            (0, 0, 0, 255))
    #overrideFont.applyOffset(font)
    overrideFont.setOffset(2)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBoldStart(boldFont)
    textBlock.setOverride(FONT_3_WORDS, overrideFont)
    textBlock.setBounds(40, 150, CARD_W - 40, 670)
    textBlock.setLineHeight(37)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(body)
    textBlock.draw(draw)

    return imageToJPEG(img)
Exemple #2
0
def actionCard(title, body, flavor, cardImage, titlesize, fontsize):
    img = getImage(cardImage)
    draw = ImageDraw.Draw(img)

    # TITLE
    font = FontData('HandelGothicDBold.otf', 39 + titlesize,
                    (255, 232, 150, 255))
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBounds(85, 70, CARD_W - 30, 150)
    textBlock.setLineHeight(39 + titlesize)
    textBlock.setCenterV(True)
    textBlock.setText(title)
    textBlock.draw(draw)

    # BODY
    body = body.replace('Action:', 'ACTION:')
    body = body.replace('Action :', 'ACTION :')
    font = FontData('MyriadProSemibold.otf', 31 + fontsize,
                    (255, 255, 255, 255))
    boldStartFont = False
    if body.startswith('ACTION'):
        boldStartFont = FontData('MyriadProBoldItalic.ttf', 31 + fontsize,
                                 (255, 255, 255, 255))
    else:
        boldStartFont = FontData('MyriadProBold.ttf', 31 + fontsize,
                                 (255, 255, 255, 255))
    overrideFont = FontData('HandelGothicDBold.otf', 24 + fontsize,
                            (255, 255, 255, 255))
    #overrideFont.applyOffset(font)
    overrideFont.setOffset(2)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBoldStart(boldStartFont)
    textBlock.setOverride(FONT_3_WORDS, overrideFont)
    textBlock.setBounds(70, 206, CARD_W - 25, CARD_H - 25)
    textBlock.setLineHeight(37 + fontsize)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(body)
    textBlock.draw(draw)

    # FLAVOR
    font = FontData('MyriadWebProItalic.ttf', 27 + fontsize,
                    (255, 255, 255, 255))
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setAlignBottom(True)
    textBlock.setBounds(70, 206, CARD_W - 25, CARD_H - 25)
    textBlock.setLineHeight(31 + fontsize)
    textBlock.setText(flavor)
    y, h = textBlock.draw(draw)
    y = (y - h) - 15
    draw.line([(107, y), (CARD_W - 69, y)], fill=(255, 255, 255, 255), width=2)

    return imageToJPEG(img)
Exemple #3
0
def agendaCard(title, type, body, cardImage, titlesize, fontsize, gradual):
    img = getImage(cardImage)
    draw = ImageDraw.Draw(img)

    x = 200
    y = 160
    w = 100
    h = 30
    color = (24, 26, 25, 255)
    draw.rectangle([(x, y), (x + w, y + h)], color)

    # TITLE
    font = FontData('HandelGothicDBold.otf', 44 + titlesize,
                    (149, 202, 255, 255))
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(30, 40, CARD_W - 30, 120)
    textBlock.setLineHeight(44 + titlesize)
    textBlock.setCenterV(True)
    textBlock.setText(title)
    textBlock.draw(draw)

    # TYPE
    items = type.split('|')
    type = items[0]
    color = ImageColor.getrgb('#' + items[1])
    font = FontData('HandelGothicDBold.otf', 31, color)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(0, 160, CARD_W, 190)
    textBlock.setLineHeight(31)
    textBlock.setText(type)
    textBlock.draw(draw)

    # BODY
    font = FontData('MyriadProRegular.ttf', 28 + fontsize, (0, 0, 0, 255))
    overrideFont = FontData('HandelGothicDBold.otf', 24 + fontsize,
                            (0, 0, 0, 255))
    #overrideFont.applyOffset(font)
    overrideFont.setOffset(-1)
    y = 225

    # Tolerate odd spreadsheet text syntax.
    if '(When' in body:
        i = body.find('(When')
        j = body.find(')', i + 1)
        whenText = body[i + 1:j]
        if len(body) > j + 1 and body[j + 1] == '\n':
            j += 1
        body = body[:i] + body[j + 1:]
        textBlock = TextBlock()
        textBlock.setCenterH(True)
        textBlock.setFont(font)
        textBlock.setBounds(50, y, CARD_W - 50, 700)
        textBlock.setLineHeight(37 + fontsize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setText(whenText)
        y, _ = textBlock.draw(draw)
        y += textBlock._lineH * (PARAGRAPH_LINE_HEIGHT_SCALE - 1)

    electFr = unicode('Élisez ', 'utf-8')
    if ('Elect ' in body) or (electFr in body):
        boldFont = FontData('MyriadProBold.ttf', 28 + fontsize, (0, 0, 0, 255))
        for line in filter(None, body.split('\n')):
            textBlock = TextBlock()
            textBlock.setCenterH(True)
            textBlock.setFont(font)
            textBlock.setOverride(FONT_3_WORDS, overrideFont)
            textBlock.setBounds(50, y, CARD_W - 50, 700)
            textBlock.setLineHeight(37 + fontsize)
            textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
            textBlock.setGradualShrink(gradual)
            if line.startswith('Elect ') or line.startswith(electFr):
                textBlock.setFont(boldFont)
            textBlock.setText(line.strip())
            y, _ = textBlock.draw(draw)
            y += textBlock._lineH * (PARAGRAPH_LINE_HEIGHT_SCALE - 1)

    elif ('For: ' in body) or ('Pour :' in body):
        startFont = FontData('MyriadProSemiboldItalic.ttf', 28 + fontsize,
                             (0, 0, 0, 255))
        for line in filter(None, body.split('\n')):
            isFor = line.startswith('For:') or line.startswith('Pour :')
            isAgainst = line.startswith('Against:') or line.startswith(
                'Contre :')
            textBlock = TextBlock()
            textBlock.setFont(font)
            textBlock.setOverride(FONT_3_WORDS, overrideFont)
            textBlock.setBounds(50, y, CARD_W - 50, 700)
            textBlock.setLineHeight(37 + fontsize)
            textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
            textBlock.setGradualShrink(gradual)
            if isFor or isAgainst:
                textBlock.setBoldStart(startFont)
                textBlock.setIndent(20)
            textBlock.setText(line.strip())
            y, _ = textBlock.draw(draw)
            y += textBlock._lineH * (PARAGRAPH_LINE_HEIGHT_SCALE - 1)

    else:
        textBlock = TextBlock()
        textBlock.setCenterH(True)
        textBlock.setFont(font)
        textBlock.setOverride(FONT_3_WORDS, overrideFont)
        textBlock.setBounds(65, y, CARD_W - 65, 700)
        textBlock.setLineHeight(37 + fontsize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setText(body)
        textBlock.setGradualShrink(gradual)
        y, _ = textBlock.draw(draw)

    return imageToJPEG(img)