"""Steam capsules from the key art in Docs/Steam/source. python Tools/Steam/capsules.py [out dir] The wide art (keyart_user_wide.webp) makes the wide capsules, the hero and the page background; the tall one with more sky drawn on above it (keyart_user_tall_sky.png: the original pasted back over a gpt-image outpaint) makes the tall ones. Writes to Docs/Steam/capsules by default. The icons and the library logo are not made here. """ import sys, os from PIL import Image, ImageFilter, ImageEnhance ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'Docs', 'Steam') OUT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(ROOT, 'capsules') os.makedirs(OUT, exist_ok=True) wide = Image.open(os.path.join(ROOT, 'source', 'keyart_user_wide.webp')).convert('RGB') logo = Image.open(os.path.join(ROOT, 'source', 'logo_clean.png')).convert('RGBA') logo = logo.crop(logo.getbbox()) tall = Image.open(os.path.join(ROOT, 'source', 'keyart_user_tall_sky.png')).convert('RGB') def cover(img, W, H, fx=0.5, fy=0.5, zoom=1.0): """Scales to cover W x H (times zoom), then crops around the focus fx, fy (0..1 of the free room).""" k = max(W / img.width, H / img.height) * zoom im = img.resize((max(W, round(img.width * k)), max(H, round(img.height * k))), Image.LANCZOS) x = round((im.width - W) * fx) y = round((im.height - H) * fy) im = im.crop((x, y, x + W, y + H)) if k > 1.2: im = im.filter(ImageFilter.UnsharpMask(radius=2, percent=60, threshold=2)) return im def put_logo(im, cx, cy, width): """The logo with its width in pixels, centred on cx, cy (fractions), with a soft shadow under it.""" lw = round(width) lh = round(logo.height * lw / logo.width) lg = logo.resize((lw, lh), Image.LANCZOS) x = round(im.width * cx - lw / 2) y = round(im.height * cy - lh / 2) sh = Image.new('RGBA', lg.size, (10, 30, 60, 0)) a = lg.split()[3].point(lambda v: int(v * 0.45)) sh.putalpha(a) pad = max(4, lw // 25) shadow = Image.new('RGBA', (lw + pad * 4, lh + pad * 4), (0, 0, 0, 0)) shadow.paste(sh, (pad * 2, pad * 2), sh) shadow = shadow.filter(ImageFilter.GaussianBlur(pad)) base = im.convert('RGBA') base.alpha_composite(shadow, (x - pad * 2 + pad // 2, y - pad * 2 + pad)) base.alpha_composite(lg, (x, y)) return base.convert('RGB') def save(im, name): p = os.path.join(OUT, name) if name.endswith('.jpg'): im.save(p, quality=92) else: im.save(p, optimize=True) print(name, im.size) # the wide art: planet left of centre, open sky right of it, the crew along the bottom main = put_logo(cover(wide, 1232, 706, 0.5, 0.5), 0.775, 0.235, 1232 * 0.40) save(main, 'main_capsule_1232x706.png') head = put_logo(cover(wide, 920, 430, 0.5, 0.9), 0.765, 0.25, 920 * 0.42) save(head, 'header_capsule_920x430.png') save(head, 'library_header_920x430.png') small = put_logo(cover(wide, 462, 174, 0.5, 0.75), 0.5, 0.5, 462 * 0.62) save(small, 'small_capsule_462x174.png') save(cover(wide, 3840, 1240, 0.5, 0.93), 'library_hero_3840x1240.png') ev = put_logo(cover(wide, 1920, 622, 0.5, 0.95), 0.79, 0.3, 1920 * 0.28) save(ev, 'event_header_1920x622.png') save(put_logo(cover(wide, 800, 450, 0.5, 0.5), 0.765, 0.25, 800 * 0.42), 'event_cover_800x450.png') bg = cover(wide, 1438, 810, 0.5, 0.5).filter(ImageFilter.GaussianBlur(10)) bg = ImageEnhance.Brightness(bg).enhance(0.55) bg = ImageEnhance.Color(bg).enhance(0.8) save(bg, 'page_background_1438x810.png') if True: # the tall art with the sky drawn on above it: the logo goes in that sky save(put_logo(cover(tall, 600, 900, 0.5, 0.0), 0.5, 0.155, 600 * 0.86), 'library_capsule_600x900.png') save(put_logo(cover(tall, 748, 896, 0.5, 0.6), 0.5, 0.152, 748 * 0.66), 'vertical_capsule_748x896.png')