File size: 1,164 Bytes
251956d aa5697c ee26142 88f0944 ee26142 963e07a aa5697c ee26142 aa5697c ee26142 aa5697c 88f0944 aa5697c 88f0944 aa5697c 88f0944 aa5697c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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()
|