Skip to content

Life #48

@Wylss

Description

@Wylss

from PIL import Image, ImageDraw, ImageFont

Create a blank white image

width, height = 800, 1200
image = Image.new("RGB", (width, height), "white")
draw = ImageDraw.Draw(image)

Define fonts

title_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 40)
subtitle_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 30)
text_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 25)
program_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 23)
small_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20)

Texts to be written on the image

title = "La Journée de l'Agronome !!!"
subtitle = "Sous le haut parrainage du Ministre de l'Agriculture,\nde l'Élevage et de la Pêche Jonathan IGNOUMBA"
date_time = "Samedi 22 juin 2024 à partir de 8h00"
location = "Campus de l'EM Gabon Université,\nnon loin du rond-point pavé de Mindoubé 2"
theme = "Le défi de la sécurité alimentaire au Gabon,\nenjeux stratégique pour le développement"
program_title = "Au programme :"
program_items = [
"Conférence",
"Animation des stands et vente des produits\nagricoles bio, au prix de rien"
]
invitation = "La journée de l'Agronome, le défi de la Sécurité\nAlimentaire au Gabon !"

Calculate text positions

title_y = 50
subtitle_y = title_y + 80
date_time_y = subtitle_y + 100
location_y = date_time_y + 60
theme_y = location_y + 80
program_title_y = theme_y + 100
program_items_y = program_title_y + 50
invitation_y = program_items_y + 100

Draw text on the image

draw.text((width//2, title_y), title, font=title_font, fill="black", anchor="mm")
draw.text((width//2, subtitle_y), subtitle, font=subtitle_font, fill="black", anchor="mm")
draw.text((width//2, date_time_y), date_time, font=text_font, fill="black", anchor="mm")
draw.text((width//2, location_y), location, font=text_font, fill="black", anchor="mm")
draw.text((width//2, theme_y), theme, font=text_font, fill="black", anchor="mm")
draw.text((width//2, program_title_y), program_title, font=text_font, fill="black", anchor="mm")
for i, item in enumerate(program_items):
draw.text((width//2, program_items_y + i*40), item, font=program_font, fill="black", anchor="mm")
draw.text((width//2, invitation_y), invitation, font=text_font, fill="black", anchor="mm")

Save the image

image_path = "/mnt/data/affiche_publicitaire.png"
image.save(image_path)

image.show()
image_path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions