chessbaseLinux/website/shots/derive.py
vrubelroman ed0e3b1fe1
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run
A new icon everywhere: the penguin in a crown (icons/icon2.png)
packaging/icons/make-icons.sh makes every icon from one picture: the Linux hicolor PNGs
(the macOS .icns and the packages take them), the window icon, the Windows .ico, the
Android adaptive foreground (62 % of the 108 dp canvas) and a solid monochrome one for
themed icons, the site's tab, header and iOS icons. The site's link preview takes the
transparent icon and names Android too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 15:20:01 +03:00

70 lines
3 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 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()
og_image()