File size: 580 Bytes
345855e | 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 | # publisher/thumbnail_engine.py
from PIL import Image, ImageDraw, ImageFont
from pathlib import Path
def generate_thumbnail(text, output):
img = Image.new("RGB", (1080,1080), "black")
draw = ImageDraw.Draw(img)
font_path = Path(__file__).resolve().parents[1] / "fonts" / "TikTok-Bold.ttf"
try:
font = ImageFont.truetype(str(font_path), 80)
except Exception:
font = ImageFont.load_default()
draw.text((80,400), text[:60], font=font, fill="white")
Path(output).parent.mkdir(exist_ok=True)
img.save(output)
return output
|