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 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)