LoFinity / scripts /make_og.py
eloigil6's picture
Update README and index.html for enhanced metadata and visuals. Added a thumbnail link to README and improved SEO with Open Graph and Twitter meta tags in index.html, including updated title and description for better social sharing.
5f70190
Raw
History Blame Contribute Delete
1.2 kB
"""Fit a screenshot into the 1200x630 Open Graph image for the Space.
Cover-crops (scale-to-fill, centred) the given image to 1200x630 and writes
frontend/og.png — the file the OG tags in index.html and the README thumbnail
point at. Pass a screenshot of the app; re-run whenever you want a new one.
python scripts/make_og.py ~/Desktop/shot.png
"""
import sys
from pathlib import Path
from PIL import Image
ROOT = Path(__file__).resolve().parent.parent
OUT = ROOT / "frontend" / "og.png"
W, H = 1200, 630 # the ratio Discord/OG previews expect (1.91:1)
def main():
if len(sys.argv) < 2:
print("usage: python scripts/make_og.py <screenshot>")
return 1
src = Image.open(sys.argv[1]).convert("RGB")
sw, sh = src.size
scale = max(W / sw, H / sh) # cover: fill the frame, crop the overflow
resized = src.resize((round(sw * scale), round(sh * scale)), Image.LANCZOS)
nw, nh = resized.size
left, top = (nw - W) // 2, (nh - H) // 2
resized.crop((left, top, left + W, top + H)).save(OUT, "PNG", optimize=True)
print(f"wrote {OUT.relative_to(ROOT)} ({OUT.stat().st_size // 1024} KB, {W}x{H})")
if __name__ == "__main__":
sys.exit(main())