chessbaseLinux/website/shots/derive.py
vrubelroman 12e4c7d5e9
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run
Website: Android screenshots first for a visitor on Android
Seven phone screens one by one (home with a put-aside game, a database's
games, the Opera game, Stockfish, the play sheet, «Who to play», a game
against Rodent IV) open the gallery and the lightbox on Android, under «On
the phone», before «On the computer»; the hero shows the four phone screens.
Other visitors see the page as before. Nine languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 15:47:09 +03:00

87 lines
3.8 KiB
Python

#!/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 derive_phone():
"""The Android screens (1080x2400, shots/raw/phone): narrow thumbnails for the gallery."""
out = os.path.join(OUT, "phone")
os.makedirs(out, exist_ok=True)
for path in sorted(glob.glob(os.path.join(RAW, "phone", "[0-9]*.png"))):
stem = os.path.splitext(os.path.basename(path))[0]
im = Image.open(path).convert("RGB")
for w in (360, 720, 1080):
small = im if w == im.width else 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 (360, 720):
small.save(os.path.join(out, f"{stem}-{w}.jpg"), "JPEG", quality=86, optimize=True, progressive=True)
im.save(os.path.join(out, f"{stem}.png"), "PNG", optimize=True)
print("phone/" + 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)
# The transparent icon (the site's 180 px one has a background for iOS).
icon_path = os.path.join(os.path.dirname(STATIC), "..", "packaging", "icons", "hicolor", "256x256", "apps", "io.github.vrubelroman.chessPenguin.png")
icon = Image.open(icon_path).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))
d.text((64, 370), "Free chess database software", font=font(False, 34), fill=(163, 167, 173))
d.text((64, 416), "for Windows, macOS, Linux and Android", font=font(False, 34), fill=(163, 167, 173))
img.save(os.path.join(STATIC, "og-image.png"), "PNG", optimize=True)
print("og-image.png")
if __name__ == "__main__":
derive()
derive_phone()
og_image()