Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
0
def nobilityCard(color, title, type, body, footer, points, titlesize,
                 fontsize):
    filename = 'Nobility' + color + '.jpg'
    img = getImage(filename)
    draw = ImageDraw.Draw(img)

    # TITLE
    font = FontData('HandelGothicDBold.otf', 44 + titlesize,
                    (255, 255, 255, 255))
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(30, 20, CARD_W - 30, 100)
    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(50, 130, 450, 160)
    textBlock.setLineHeight(31)
    textBlock.setText(type)
    textBlock.draw(draw)

    # BODY
    font = FontData('MyriadProSemibold.otf', 39 + fontsize,
                    (255, 255, 255, 255))
    overrideFont = FontData('HandelGothicDBold.otf', 33 + fontsize,
                            (255, 255, 255, 255))
    #overrideFont.applyOffset(font)
    overrideFont.setOffset(0)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setOverride(FONT_3_WORDS, overrideFont)
    textBlock.setCenterH(True)
    textBlock.setCenterV(True)
    textBlock.setBounds(25, 206, CARD_W - 25, 560)
    textBlock.setLineHeight(48 + fontsize)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(body)
    textBlock.draw(draw)

    # FOOTER
    color = (255, 255, 255, 255) if footer.lower() == 'public' else (255, 0, 0,
                                                                     255)
    font = FontData('MyriadProBold.ttf', 40, color)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(25, 520, CARD_W - 25, 560)
    textBlock.setLineHeight(40)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(footer)
    textBlock.draw(draw)

    # POINTS
    color = (255, 255, 255, 255) if footer.lower() == 'public' else (255, 0, 0,
                                                                     255)
    font = FontData('HandelGothicDBold.otf', 130, color)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(200, 565, 300, 700)
    textBlock.setLineHeight(130)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(points)
    textBlock.draw(draw)

    return imageToJPEG(img)
Beispiel #4
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)
Beispiel #5
0
def publicObjectiveCard(level, title, type, body, footer, cardImage, titlesize,
                        fontsize):
    img = getImage(cardImage)
    draw = ImageDraw.Draw(img)

    x = 125
    y = 130
    w = 250
    h = 30
    color = (12, 12, 14, 255)
    draw.rectangle([(x, y), (x + w, y + h)], color)

    x = 100
    y = 710
    w = 300
    h = 30
    color = (12, 12, 14, 255)
    draw.rectangle([(x, y), (x + w, y + h)], color)

    # TITLE
    color = ImageColor.getrgb('#ffb732') if level == 1 else ImageColor.getrgb(
        '#9999ff')
    font = FontData('HandelGothicDBold.otf', 43 + titlesize, color)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(30, 20, CARD_W - 30, 100)
    textBlock.setLineHeight(43 + titlesize)
    textBlock.setCenterV(True)
    textBlock.setText(title)
    textBlock.draw(draw)
    textBlock.drawGradient(img, font.getColor(), (255, 255, 255, 255))

    # 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, 130, CARD_W, 160)
    textBlock.setLineHeight(31)
    textBlock.setText(type)
    textBlock.draw(draw)

    # BODY
    font = FontData('MyriadProSemibold.otf', 39 + fontsize,
                    (255, 255, 255, 255))
    overrideFont = FontData('HandelGothicDBold.otf', 33 + fontsize,
                            (255, 255, 255, 255))
    #overrideFont.applyOffset(font)
    overrideFont.setOffset(0)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setOverride(FONT_3_WORDS, overrideFont)
    textBlock.setCenterH(True)
    textBlock.setCenterV(True)
    textBlock.setBounds(50, 206, CARD_W - 50, 560)
    textBlock.setLineHeight(48 + fontsize)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(body)
    y, h = textBlock.draw(draw)

    # FOOTER
    items = footer.split('|')
    footer = items[0]
    color = ImageColor.getrgb('#ffb732') if level == 1 else ImageColor.getrgb(
        '#9999ff')
    font = FontData('HandelGothicDBold.otf', 32, color)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setCenterH(True)
    textBlock.setBounds(0, 705, CARD_W, 740)
    textBlock.setLineHeight(32)
    textBlock.setText(footer)
    y, h = textBlock.draw(draw)
    textBlock.drawGradient(img, font.getColor(), (255, 255, 255, 255))

    return imageToJPEG(img)
Beispiel #6
0
def unitCard(content, prereqs, stats, titlesize, fontsize):
    img = getImage('jaheit_unit_upgrade/background.jpg')
    img = img.convert('RGBA')
    draw = ImageDraw.Draw(img)

    # Solid block, use alpha blend with an overlay.
    subtitleColor = content['subtitleColor']
    solid = Image.new('RGBA', (CARD_W, CARD_H), ImageColor.getrgb('#' + subtitleColor))

    # UNIT IMAGE
    unitImage = content['unitImage']
    if unitImage and len(unitImage) > 0:
        overlay = getImage('jaheit_unit_upgrade/' + unitImage)
        img.paste(overlay, (0, 0), overlay)

    # FACTION
    factionImage = content['factionImage']
    if factionImage != '' and factionImage != 'BLANK':
        factionImg = getImage('faction_icons/' + factionImage)
        factionImg = factionImg.resize((200, 200))
        img.paste(factionImg, (-40, -45), factionImg)

    # TITLE
    title = content['title']
    titleLeft = 60 if factionImage == '' else 120
    color = (255, 255, 255, 255)
    font = FontData('HandelGothicDBold.otf', 39 + titlesize, color)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBounds(titleLeft, 0, CARD_W - 60, 70)
    textBlock.setLineHeight(font._fontSize + titlesize)
    textBlock.setCenterV(True)
    textBlock.setText(title)
    textBlock.draw(draw)
    generates = stats['generates']
    if generates and len(generates) > 0:
        if generates == 'green':
            color = ImageColor.getrgb('#178414')
        elif generates == 'blue':
            color = ImageColor.getrgb('#95caff')
        elif generates == 'red':
            color = ImageColor.getrgb('#b93340')
        elif generates == 'yellow':
            color = ImageColor.getrgb('#e5dc76')
        textBlock.drawGradient(img, color, (255, 255, 255, 255))

    # SUBTITLE
    subtitle = content['subtitle']
    subtitleColor = content['subtitleColor']
    if subtitle and len(subtitle) > 0:
        color = ImageColor.getrgb('#' + subtitleColor)
        font = FontData('HandelGothicDBold.otf', 26, color)
        textBlock = TextBlock()
        textBlock.setFont(font)
        textBlock.setBounds(titleLeft, 70, CARD_W - 60, 115)
        textBlock.setLineHeight(font._fontSize + titlesize)
        textBlock.setCenterV(True)
        textBlock.setText(subtitle)
        textBlock.draw(draw)

    # BODY
    body = content['body']
    top = 135 if subtitle == '' else 135
    font = FontData('MyriadProSemibold.otf', 31 + fontsize, (255, 255, 255, 255))
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBounds(100, top, CARD_W - 50, CARD_H - 25)
    textBlock.setLineHeight(font._fontSize + fontsize)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(body)
    y, h = textBlock.draw(draw)

    # ATTRIBUTES
    attributes = content['attributes']
    top = y + 15
    font = FontData('HandelGothicDBold.otf', 28 + fontsize, (255, 255, 255, 255))
    overrideFont = FontData('PierreDingbats.ttf', 24 + fontsize, (255, 255, 255, 255))
    overrideFont.setOffset(4)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBounds(100, top, CARD_W - 50, 325)
    textBlock.setLineHeight(font._fontSize + fontsize)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setAlignBottom(True)
    textBlock.setText(attributes.replace('* ', 'F '))
    textBlock.setOverride({'F'}, overrideFont)
    textBlock.draw(draw)

    # PREREQ FRAME
    prereqCount = prereqs['r'] + prereqs['y'] + prereqs['b'] + prereqs['g']
    if prereqCount > 0 and prereqCount <= 4:
        frameImg = getImage('jaheit_unit_upgrade/prereq_' + str(prereqCount) + '.png')
        img.paste(frameImg, (0, 0), frameImg)

    # PREREQS
    w, h = 55, 77
    x = 15
    y = 500 - h - 7
    if prereqs['r'] > 0:
        preImg = getImage('jaheit_unit_upgrade/prereq_red.png')
        ix = x + w / 2
        iw, ih = preImg.size
        for _ in range(prereqs['r']):
            iy = y + h / 2
            img.paste(preImg, (ix - iw / 2, iy - ih / 2), preImg)
            y -= h
    if prereqs['y'] > 0:
        preImg = getImage('jaheit_unit_upgrade/prereq_yellow.png')
        ix = x + w / 2
        iw, ih = preImg.size
        for _ in range(prereqs['y']):
            iy = y + h / 2
            img.paste(preImg, (ix - iw / 2, iy - ih / 2), preImg)
            y -= h
    if prereqs['b'] > 0:
        preImg = getImage('jaheit_unit_upgrade/prereq_blue.png')
        ix = x + w / 2
        iw, ih = preImg.size
        for _ in range(prereqs['b']):
            iy = y + h / 2
            img.paste(preImg, (ix - iw / 2, iy - ih / 2), preImg)
            y -= h
    if prereqs['g'] > 0:
        preImg = getImage('jaheit_unit_upgrade/prereq_green.png')
        ix = x + w / 2
        iw, ih = preImg.size
        for _ in range(prereqs['g']):
            iy = y + h / 2
            img.paste(preImg, (ix - iw / 2, iy - ih / 2), preImg)
            y -= h

    # BOTTOM COST
    fontValue = FontData('HandelGothicDBold.otf', 100, (255, 255, 255, 255))
    fontLabel = FontData('HandelGothicDBold.otf', 26, (255, 255, 255, 255))
    cost = stats['cost']
    if cost > 0:
        overlay = getImage('jaheit_unit_upgrade/bot_cost.png')
        img.paste(solid, (0, 0), overlay)
        img.paste(solid, (0, 0), overlay)  # again, for better visibility

        left = 88
        right = left + 162
        textBlock = TextBlock()
        textBlock.setFont(fontLabel)
        textBlock.setBounds(left, 450, right, 475)
        textBlock.setLineHeight(fontLabel._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText('COST')
        textBlock.draw(draw)

        if content['unitImage'] == 'bg_fighter.png':
            right -= 30
            x2 = getImage('jaheit_unit_upgrade/bot_cost_fighter_x2.png')
            img.paste(x2, (25, 0), x2)
        if content['unitImage'] == 'bg_infantry.png':
            right -= 30
            x2 = getImage('jaheit_unit_upgrade/bot_cost_infantry_x2.png')
            img.paste(x2, (25, 0), x2)

        textBlock = TextBlock()
        textBlock.setFont(fontValue)
        textBlock.setBounds(left, 335, right, 442)
        textBlock.setLineHeight(fontValue._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText(str(cost))
        textBlock.draw(draw)

    # BOTTOM COMBAT
    combat = stats['combat']
    combatDice = stats['combatDice']
    if combat > 0:
        overlay = getImage('jaheit_unit_upgrade/bot_combat.png')
        img.paste(solid, (0, 0), overlay)
        img.paste(solid, (0, 0), overlay)  # again, for better visibility

        left = 256
        right = left + 162
        textBlock = TextBlock()
        textBlock.setFont(fontLabel)
        textBlock.setBounds(left, 450, right, 475)
        textBlock.setLineHeight(fontLabel._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText('COMBAT')
        textBlock.draw(draw)

        if combatDice == 2:
            right -= 30
            x2 = getImage('jaheit_unit_upgrade/bot_combat_x2.png')
            img.paste(x2, (0, 0), x2)
        if combatDice == 3:
            right -= 30
            x2 = getImage('jaheit_unit_upgrade/bot_combat_x3.png')
            img.paste(x2, (0, 0), x2)

        textBlock = TextBlock()
        textBlock.setFont(fontValue)
        textBlock.setBounds(left, 335, right, 442)
        textBlock.setLineHeight(fontValue._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText(str(combat))
        textBlock.draw(draw)

    # BOTTOM MOVE
    move = stats['move']
    if move > 0:
        overlay = getImage('jaheit_unit_upgrade/bot_move.png')
        img.paste(solid, (0, 0), overlay)
        img.paste(solid, (0, 0), overlay)  # again, for better visibility

        left = 424
        right = left + 162
        textBlock = TextBlock()
        textBlock.setFont(fontLabel)
        textBlock.setBounds(left, 450, right, 475)
        textBlock.setLineHeight(fontLabel._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText('MOVE')
        textBlock.draw(draw)

        textBlock = TextBlock()
        textBlock.setFont(fontValue)
        textBlock.setBounds(left, 335, right, 442)
        textBlock.setLineHeight(fontValue._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText(str(move))
        textBlock.draw(draw)

    # BOTTOM CAPACITY
    capacity = stats['capacity']
    if capacity > 0:
        overlay = getImage('jaheit_unit_upgrade/bot_capacity.png')
        img.paste(solid, (0, 0), overlay)
        img.paste(solid, (0, 0), overlay)  # again, for better visibility

        left = 593
        right = left + 162
        textBlock = TextBlock()
        textBlock.setFont(fontLabel)
        textBlock.setBounds(left, 450, right, 475)
        textBlock.setLineHeight(fontLabel._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText('CAPACITY')
        textBlock.draw(draw)

        textBlock = TextBlock()
        textBlock.setFont(fontValue)
        textBlock.setBounds(left, 335, right, 442)
        textBlock.setLineHeight(fontValue._fontSize)
        textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
        textBlock.setCenterH(True)
        textBlock.setText(str(capacity))
        textBlock.draw(draw)

    # BOTTOM GENERATES -- OR -- SPACER
    generates = stats['generates']
    if generates and len(generates) > 0:
        overlay = getImage('jaheit_unit_upgrade/generate_' + generates + '.png')
        img.paste(overlay, (0, 0), overlay)
    else:
        botSpacer = False
        if cost == 0 and combat == 0 and move == 0 and capacity == 0:
            botSpacer = 'jaheit_unit_upgrade/bot_spacer_4.png'
        elif move == 0 and capacity == 0:
            botSpacer = 'jaheit_unit_upgrade/bot_spacer_2.png'
        elif capacity == 0:
            botSpacer = 'jaheit_unit_upgrade/bot_spacer_1.png'
        if botSpacer:
            overlay = getImage(botSpacer)
            img.paste(solid, (0, 0), overlay)
            img.paste(solid, (0, 0), overlay)  # again, for better visibility

    img = img.convert('RGB')
    return imageToJPEG(img)
Beispiel #7
0
def techCard(faction, title, body, preG, preB, preY, preR, generates,
             titlesize, fontsize):
    cardName = 'Tech_0_blank.jpg'
    count = preG + preB + preY + preR
    if count == 1:
        cardName = 'Tech_1_blank.jpg'
    if count == 2:
        cardName = 'Tech_2_blank.jpg'
    if count == 3:
        cardName = 'Tech_3_blank.jpg'

    img = getImage(cardName)
    img = img.convert('RGBA')
    draw = ImageDraw.Draw(img)

    titleLeft = 60

    # FACTION
    if faction != '':
        titleLeft = 120
        x = 0
        y = 0
        w = 120
        h = 120
        color = (12, 12, 14, 255)
        #draw.rectangle([(x, y), (x+w, y+h)], color)
        if faction != 'Blank':
            factionImg = getImage('faction_icons/' + faction)
            factionImg = factionImg.resize((200, 200))
            img.paste(factionImg, (-40, -45), factionImg)

    color = (255, 255, 255, 255)

    if generates == 'green':
        color = ImageColor.getrgb('#178414')
    elif generates == 'blue':
        color = ImageColor.getrgb('#95caff')
    elif generates == 'red':
        color = ImageColor.getrgb('#b93340')
    elif generates == 'yellow':
        color = ImageColor.getrgb('#e5dc76')

    # TITLE
    font = FontData('HandelGothicDBold.otf', 39 + titlesize, color)
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBounds(titleLeft, 0, CARD_W - 60, 70)
    textBlock.setLineHeight(39 + titlesize)
    textBlock.setCenterV(True)
    textBlock.setText(title)
    textBlock.draw(draw)
    textBlock.drawGradient(img, color, (255, 255, 255, 255))

    # BODY
    top = 100 if faction == '' else 100
    font = FontData('MyriadProSemibold.otf', 31 + fontsize,
                    (255, 255, 255, 255))
    textBlock = TextBlock()
    textBlock.setFont(font)
    textBlock.setBounds(110, top, CARD_W - 50, CARD_H - 25)
    textBlock.setLineHeight(37 + fontsize)
    textBlock.setNewlineScale(PARAGRAPH_LINE_HEIGHT_SCALE)
    textBlock.setText(body)
    textBlock.draw(draw)

    # GENERATES
    if generates != 'none':
        genImg = getImage('Tech_Generates_' + generates.capitalize() + '.jpg')
        w, h = 160, 160
        genImg = genImg.resize((w, h))
        img.paste(genImg, (750 - w, 500 - h))

    # PREREQS
    w, h = 78, 78
    x = 4
    y = 500 - h - 12
    if preR > 0:
        preImg = getImage('Tech_Prereq_Red.png')
        preImg = preImg.resize((w, h))
        for _ in range(preR):
            img.paste(preImg, (x, y), preImg)
            y -= h
    if preY > 0:
        preImg = getImage('Tech_Prereq_Yellow.png')
        preImg = preImg.resize((w, h))
        for _ in range(preY):
            img.paste(preImg, (x, y), preImg)
            y -= h
    if preB > 0:
        preImg = getImage('Tech_Prereq_Blue.png')
        preImg = preImg.resize((w, h))
        for _ in range(preB):
            img.paste(preImg, (x, y), preImg)
            y -= h
    if preG > 0:
        preImg = getImage('Tech_Prereq_Green.png')
        preImg = preImg.resize((w, h))
        for _ in range(preG):
            img.paste(preImg, (x, y), preImg)
            y -= h

    img = img.convert('RGB')
    return imageToJPEG(img)