| # 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 | |