Exemplo n.º 1
0
def GenerateCard5Titles(Language, item):

    card = Image.new("RGBA", (384, 50))

    canvas = ImageDraw.Draw(card)

    if Language == "ja":
        font = ImageFont.truetype('assets/Fonts/NotoSansJP-Bold.otf', 15)
    elif Language == "ko":
        font = ImageFont.truetype('assets/Fonts/NotoSansKR-Regular.otf', 15)
    else:
        font = ImageFont.truetype('assets/Fonts/burbanksmall-black.otf', 15)

    title = item["title"]
    title = title.upper()

    icon = item["image"]
    icon = ImageUtil.Download(item, icon)
    icon = ImageUtil.RatioResize(item, icon, 384, 216)
    card.paste(icon, ImageUtil.CenterX(item, icon.width, card.width))

    ### 1920 * 1080 = 384
    try:
        TINT_COLOR = (0, 0, 205)  # Black
        TRANSPARENCY = 0.7  # Degree of transparency, 0-100%
        OPACITY = int(255 * TRANSPARENCY)

        cardBottom = Image.new("RGBA", (384, 360), TINT_COLOR)
        draw = ImageDraw.Draw(cardBottom)
        draw.rectangle(((384, 360), (0, 0)), fill=TINT_COLOR + (OPACITY, ))
    except Exception as e:
        print(e)
    card.paste(cardBottom, (0, 0), cardBottom)

    textWidth, _ = font.getsize(title)
    if textWidth >= 364:
        # Ensure that the item name does not overflow
        if Language == "ja":
            font, textWidth = ImageUtil.FitTextX2(item, title, 16, 1920)
        elif Language == "ko":
            font, textWidth = ImageUtil.FitTextX1(item, title, 16, 1920)
        else:
            font, textWidth = ImageUtil.FitTextX(item, title, 16, 1920)
    canvas.text(
        ImageUtil.CenterX(item, textWidth, card.width, 15),
        title,
        (255, 255, 255),
        font=font,
    )

    return card