|
from PIL import Image, ImageDraw, ImageFont |
|
import os |
|
|
|
|
|
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) |
|
|
|
|
|
img = Image.new("RGB", (600, 200), color=(255, 255, 255)) |
|
draw = ImageDraw.Draw(img) |
|
|
|
|
|
text = "Hello, 2024" |
|
|
|
|
|
x, y = 10, 50 |
|
|
|
|
|
for char in text: |
|
if char.isdigit(): |
|
|
|
font = font_outline |
|
else: |
|
|
|
font = font_regular |
|
|
|
|
|
left, top, right, bottom = font.getbbox(char) |
|
width = right - left |
|
height = bottom - top |
|
|
|
|
|
draw.text((x, y), char, font=font, fill=(0, 0, 0)) |
|
|
|
|
|
x += width |
|
|
|
|
|
img.show() |
|
|