2026-10-19 11:00:10 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""Images for the website from the raw screenshots (website/shots/raw):
|
|
|
|
|
WebP and JPEG at 640/1280/1920 px wide for the gallery and the lightbox, a PNG at
|
|
|
|
|
2560 px for "Open full size", and og-image.png (1200x630) for link previews.
|
|
|
|
|
|
|
|
|
|
python3 -I website/shots/derive.py
|
|
|
|
|
"""
|
|
|
|
|
import glob
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
RAW = os.path.join(ROOT, "shots", "raw")
|
|
|
|
|
OUT = os.path.join(ROOT, "static", "screenshots")
|
|
|
|
|
STATIC = os.path.join(ROOT, "static")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def font(bold, size):
|
|
|
|
|
name = "sans-serif:bold" if bold else "sans-serif"
|
|
|
|
|
try:
|
|
|
|
|
path = subprocess.run(["fc-match", "-f", "%{file}", name], capture_output=True, text=True).stdout
|
|
|
|
|
return ImageFont.truetype(path, size)
|
|
|
|
|
except Exception:
|
|
|
|
|
return ImageFont.load_default()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def derive():
|
|
|
|
|
for path in sorted(glob.glob(os.path.join(RAW, "[0-9]*.png"))):
|
|
|
|
|
stem = os.path.splitext(os.path.basename(path))[0]
|
|
|
|
|
im = Image.open(path).convert("RGB")
|
|
|
|
|
for w in (640, 1280, 1920):
|
|
|
|
|
small = im.resize((w, round(im.height * w / im.width)), Image.LANCZOS)
|
|
|
|
|
small.save(os.path.join(OUT, f"{stem}-{w}.webp"), "WEBP", quality=84, method=6)
|
|
|
|
|
if w in (640, 1280):
|
|
|
|
|
small.save(os.path.join(OUT, f"{stem}-{w}.jpg"), "JPEG", quality=86, optimize=True, progressive=True)
|
|
|
|
|
full = im.resize((2560, round(im.height * 2560 / im.width)), Image.LANCZOS)
|
|
|
|
|
full.save(os.path.join(OUT, f"{stem}.png"), "PNG", optimize=True)
|
|
|
|
|
print(stem)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def og_image():
|
|
|
|
|
w, h = 1200, 630
|
|
|
|
|
img = Image.new("RGB", (w, h), (22, 23, 24))
|
|
|
|
|
shot = Image.open(os.path.join(RAW, "01-game.png")).convert("RGB")
|
|
|
|
|
# The board side of the first screenshot, on the right.
|
|
|
|
|
crop = shot.crop((0, 0, int(shot.width * 0.62), shot.height))
|
|
|
|
|
crop = crop.resize((round(crop.width * h / crop.height), h), Image.LANCZOS)
|
|
|
|
|
img.paste(crop, (w - crop.width + 160, 0))
|
|
|
|
|
shade = Image.new("L", (w, h), 0)
|
|
|
|
|
d = ImageDraw.Draw(shade)
|
|
|
|
|
for x in range(w):
|
|
|
|
|
d.line([(x, 0), (x, h)], fill=max(0, min(255, int(255 * (1 - (x - 380) / 360)))))
|
|
|
|
|
img.paste((22, 23, 24), mask=shade)
|
|
|
|
|
icon = Image.open(os.path.join(STATIC, "img", "icon-180.png")).convert("RGBA").resize((128, 128), Image.LANCZOS)
|
|
|
|
|
img.paste(icon, (64, 120), icon)
|
|
|
|
|
d = ImageDraw.Draw(img)
|
|
|
|
|
d.text((64, 280), "ChessPenguin", font=font(True, 64), fill=(232, 232, 232))
|
2026-10-19 11:58:57 +03:00
|
|
|
d.text((64, 370), "Free chess database software", font=font(False, 34), fill=(163, 167, 173))
|
|
|
|
|
d.text((64, 416), "for Windows, macOS and Linux", font=font(False, 34), fill=(163, 167, 173))
|
2026-10-19 11:00:10 +03:00
|
|
|
img.save(os.path.join(STATIC, "og-image.png"), "PNG", optimize=True)
|
|
|
|
|
print("og-image.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
derive()
|
|
|
|
|
og_image()
|