from PIL import Image, ImageDraw, ImageFont import os # Load the fonts font_path_regular = "Helvetica_Neue_LT_Std_75_Bold.otf" font_path_outline = "Helvetica_Neue_LT_Std_75_Bold_Outline.otf" font_size = 130 from PIL import Image, ImageDraw, ImageFont font_regular = ImageFont.truetype(font_path_regular, font_size) font_outline = ImageFont.truetype(font_path_outline, font_size) # Create an image with white background img = Image.new("RGB", (600, 200), color=(255, 255, 255)) draw = ImageDraw.Draw(img) # Text to display text = "Hello, 2024" # Position for drawing x, y = 10, 50 # Draw each character with the appropriate font for char in text: if char.isdigit(): # Use outline font for digits font = font_outline else: # Use regular font for other characters font = font_regular # Use getbbox to calculate the size of the character left, top, right, bottom = font.getbbox(char) width = right - left height = bottom - top # Draw the character draw.text((x, y), char, font=font, fill=(0, 0, 0)) # Update the x position for the next character x += width # Show the image img.show()