[Python] Draw text with background color

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    I want to know how can I draw text like this check image [​IMG]

    As you can see text is on a green image and text has pink color background

    My code, this is part of my code I'm using PIL

    draw = ImageDraw.Draw(background)
    font = ImageFont.truetype("assets/font2.ttf", 40)
    font2 = ImageFont.truetype("assets/font2.ttf", 70)
    arial = ImageFont.truetype("assets/font2.ttf", 30)
    name_font = ImageFont.truetype("assets/font.ttf", 30)
    para = textwrap.wrap(title, width=32)
    j = 0
    draw.text(
    (10, 10), f"{h}", fill="red", font=name_font
    )
    draw.text(
    (600, 150),
    "NOW PLAYING",
    fill="white",
    stroke_width=2,
    stroke_fill="white",
    font=font2,
    )

    Continue reading...

Compartilhe esta Página