Untitled

 avatar
unknown
plain_text
a year ago
2.2 kB
3
Indexable
from PIL import Image, ImageDraw, ImageFont

# Define the size of the infographic
width = 800
height = 2000
infographic = Image.new('RGB', (width, height), 'white')
draw = ImageDraw.Draw(infographic)

# 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", 20)

# Define colors
title_color = (0, 51, 102)
subtitle_color = (0, 102, 204)
text_color = (0, 0, 0)

# Helper function to add text with word wrap
def draw_text(draw, text, position, font, color, max_width):
    lines = []
    words = text.split()
    while words:
        line = ''
        while words and draw.textsize(line + words[0], font=font)[0] <= max_width:
            line = line + (words.pop(0) + ' ')
        lines.append(line)
    y = position[1]
    for line in lines:
        draw.text((position[0], y), line, font=font, fill=color)
        y += font.getsize(line)[1]
    return y

# Add title
title = "Explore Marrakesh & Montenegro"
draw.text((50, 50), title, font=title_font, fill=title_color)

# Add introduction
intro_marrakesh = "Marrakesh: A vibrant city in Morocco known for its bustling souks, stunning palaces, and rich history."
intro_montenegro = "Montenegro: A Balkan gem with breathtaking natural landscapes, charming coastal towns, and historic sites."
y_position = draw_text(draw, intro_marrakesh, (50, 150), text_font, text_color, 700)
y_position = draw_text(draw, intro_montenegro, (50, y_position + 20), text_font, text_color, 700)

# Add section titles
draw.text((50, y_position + 40), "Top Attractions", font=subtitle_font, fill=subtitle_color)
y_position += 90

# Add top attractions for Marrakesh
attractions_marrakesh = [
    ("Jemaa el-Fnaa", "A lively square filled with performers, food stalls, and markets."),
    ("Koutoubia Mosque", "Iconic mosque with a stunning minaret."),
    ("Bahia Palace", "Beautiful palace with intricate designs and lush gardens."),
    ("Majorelle Garden", "A serene garden with exotic plants and vibrant blue structures.")
]

#
Editor is loading...
Leave a Comment