Files
5xyourteam/tools/derive-art.py
T
martbost f6dbbfdcd3 5xYourTeam card + Draft Day art (2026-11-15, LOCAL ONLY): kie.ai tier frames, Envato rings/medals/holo/back, Draft Day confetti/spotlights/scoreboard, Champiun
- Trading cards: five kie.ai nano-banana-pro tier frames (Rookie steel, Starter silver, Pro gold trim, All-Star gold + holo,
  Hall of Fame ornate gold + laurels), F4 avatar ring + B1 rank medal per tier, F5 holo foil on Pro/All-Star/HoF, sized in cqw
- Card back from F1 (text layers hidden, green re-tinted gold): tap/Enter flips a card to the stats layout (team, how drafted,
  milestone, games played, the tier ladder); landscape, takes two grid slots. Milestones only, never earnings.
- Draft Day 1080 card: D2 spotlights, D1 gold confetti, D5 scoreboard plate (blank) for the totals
- Champiun (T3, Basic Latin WOFF subset) only for the ON THE CLOCK headline and pick numbers
- tools/derive-art.py builds the web derivatives from ../assets-src (raw packs stay out of public/); public/art/MANIFEST.md maps
  each file to its source item, author and license code; tools/art.mjs renders kit/OG/proof/tier art with the same cards
- ?v= tags bumped to 2; unit 62/62, smoke 156/156 (UI_FONTS=1), iap-tank 23/23

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 07:45:43 -06:00

134 lines
8.8 KiB
Python

# Builds the web derivatives in public/art/tc (trading cards) and public/art/dd (Draft Day card) plus the subset web font
# public/assets/champiun.woff from the licensed source packs in ../assets-src (Envato Elements, licence "5xYourTeam.com",
# certificates in ../assets-src/envato/licenses) and the kie.ai frame masters in ../assets-src/kie. The raw packs never go in
# public/: only these resized, flattened files do. Local only. Run: python tools/derive-art.py (needs Pillow, numpy, scipy,
# fontTools). See public/art/MANIFEST.md for which file comes from which item.
import os, sys, glob, colorsys
from PIL import Image, ImageFilter
import numpy as np
from scipy import ndimage as nd
Image.MAX_IMAGE_PIXELS = None
APP = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
SRC = os.path.abspath(os.path.join(APP, '..', 'assets-src'))
ENV = os.path.join(SRC, 'envato')
TC = os.path.join(APP, 'public', 'art', 'tc'); DD = os.path.join(APP, 'public', 'art', 'dd')
os.makedirs(TC, exist_ok=True); os.makedirs(DD, exist_ok=True)
TIERS = ['rookie', 'starter', 'pro', 'allstar', 'hof']
def pack(code):
d = [p for p in glob.glob(os.path.join(ENV, code + '__*')) if os.path.isdir(p)]
if not d: sys.exit('missing pack ' + code)
return d[0]
def one(code, pattern):
f = sorted(glob.glob(os.path.join(pack(code), '**', pattern), recursive=True))
f = [x for x in f if '__MACOSX' not in x]
if not f: sys.exit('missing ' + code + ' ' + pattern)
return f[0]
def trim(im):
bb = im.getchannel('A').point(lambda a: 255 if a > 8 else 0).getbbox(); return im.crop(bb)
def square(im, size):
im = trim(im); s = max(im.size); c = Image.new('RGBA', (s, s), (0, 0, 0, 0)); c.paste(im, ((s - im.width) // 2, (s - im.height) // 2))
return c.resize((size, size), Image.LANCZOS)
def save_png(im, path, colors=None):
if colors: im = im.quantize(colors=colors, method=Image.FASTOCTREE, dither=Image.FLOYDSTEINBERG)
im.save(path, optimize=True); print(os.path.relpath(path, APP), os.path.getsize(path) // 1024, 'KB')
def save_jpg(im, path, q=84):
im.convert('RGB').save(path, quality=q, optimize=True, progressive=True); print(os.path.relpath(path, APP), os.path.getsize(path) // 1024, 'KB')
# 1. card frames (kie.ai nano-banana-pro, 1696x2528 masters, 2:3) -> 600x900
KIE = {'rookie': 'r1-rookie', 'starter': 'r2-starter-b', 'pro': 'r1-pro', 'allstar': 'r1-allstar', 'hof': 'r1-hof'}
for t in TIERS:
save_jpg(Image.open(os.path.join(SRC, 'kie', KIE[t] + '.png')).convert('RGB').resize((600, 900), Image.LANCZOS), os.path.join(TC, 'frame-' + t + '.jpg'), 86)
# 2. avatar rings (F4 Tier 3D Frame, Unerispace) -> 320x320
RING = {'rookie': '18', 'starter': '20', 'pro': '12', 'allstar': '15', 'hof': '17'}
for t in TIERS:
save_png(square(Image.open(one('F4', 'Tier Frame ' + RING[t] + '.png')).convert('RGBA'), 320), os.path.join(TC, 'ring-' + t + '.png'), 200)
# 3. rank medals (B1 Game Rank Icons Vol.4, myteamart) -> 160x160
MEDAL = {'rookie': '12', 'starter': '07', 'pro': '09', 'allstar': '03', 'hof': '05'}
for t in TIERS:
save_png(square(Image.open(one('B1', 'ri_4_' + MEDAL[t] + '.png')).convert('RGBA'), 160), os.path.join(TC, 'medal-' + t + '.png'), 160)
# 4. holo foil overlay (F5 15 Holographic Foil Textures Vol.2, DavidBalev, foil 12) -> portrait 600x900
h = Image.open(one('F5', 'Holographic Foil_12.jpg')).convert('RGB'); w = int(h.height * 2 / 3)
save_jpg(h.crop(((h.width - w) // 2, 0, (h.width - w) // 2 + w, h.height)).resize((600, 900), Image.LANCZOS), os.path.join(TC, 'holo.jpg'), 78)
# 5. card back (F1 Futuristic Baseball Trading Card PSD Template, bornx): the back with every text + logo layer hidden, the
# template's green re-tinted to 5xYourTeam gold, 1125x825 -> 900x660
from psd_tools import PSDImage
p = PSDImage.open(one('F1', 'Back-Baseball-Trading-Card-Template.psd'))
for l in p.descendants():
if l.kind == 'type' or 'Logo' in l.name: l.visible = False
b = np.asarray(p.composite(force=True).convert('RGB')).astype(float) / 255
r, g, bl = b[..., 0], b[..., 1], b[..., 2]
mx = b.max(2); mn = b.min(2); green = (g > r + .08) & (g > bl + .04)
lum = (0.3 * r + 0.59 * g + 0.11 * bl)
gold = np.array([1.0, 0.788, 0.235]); deep = np.array([0.80, 0.55, 0.05])
k = np.clip((lum - 0.25) / 0.45, 0, 1)[..., None]
tint = deep * (1 - k) + gold * k
out = np.where(green[..., None], tint, b)
save_jpg(Image.fromarray((out * 255).astype('uint8')).resize((900, 660), Image.LANCZOS), os.path.join(TC, 'back.jpg'), 86)
# 6. Draft Day: gold confetti (D1, PartikusiDesign, overlay 6) 4000x2000 -> 1080x1080 transparent
c = Image.open(one('D1', '6.png')).convert('RGBA').resize((2160, 1080), Image.LANCZOS).crop((540, 0, 1620, 1080))
save_png(c, os.path.join(DD, 'confetti.png'), 128)
# 7. Draft Day: stage spotlights (D2, Pitchlook, background 2) on black, blended with screen -> 1080x1080
s = Image.open(one('D2', 'Stage Spotlight Overlay Background 2.jpg')).convert('RGB').resize((1620, 1080), Image.LANCZOS).crop((270, 0, 1350, 1080))
save_jpg(s, os.path.join(DD, 'spotlight.jpg'), 80)
# 8. Draft Day: scoreboard plate (D5, BoykoPictures). The pack is EPS + a 4167px preview on a baked checkerboard; no EPS
# rasteriser here, so the preview's checkerboard (period 4167/30 px) is modelled and removed, the board plate is cut out
# and its printed TIME / HOME / GUEST / digits are covered with the plate's own clean texture (a blank board).
im = Image.open(one('D5', 'k_049-01.jpg')).convert('RGB'); a = np.asarray(im).astype(int); L = a.mean(2); H, W = L.shape
S = W / 30.0; yy, xx = np.mgrid[0:H, 0:W]
par = (np.floor((yy + .5) / S).astype(int) + np.floor((xx + .5) / S).astype(int)) % 2
v0 = np.median(L[:130, :130]); v1 = np.median(L[:130, 145:270]); exp = np.where(par == 0, v0, v1)
band = (np.abs((yy + .5) / S - np.round((yy + .5) / S)) * S < 2) | (np.abs((xx + .5) / S - np.round((xx + .5) / S)) * S < 2)
bg = ((np.abs(L - exp) <= 7) | (band & (L > 30) & (L < 60))) & ((a.max(2) - a.min(2)) <= 10)
lab, n = nd.label(bg); edge = set(np.unique(np.concatenate([lab[0], lab[-1], lab[:, 0], lab[:, -1]]))) - {0}
fg = nd.binary_opening(~np.isin(lab, list(edge)), iterations=2)
lab2, n2 = nd.label(fg); sizes = nd.sum(fg, lab2, range(1, n2 + 1)); big = int(np.argmax(sizes)) + 1 # the board + posts
board = nd.binary_fill_holes(lab2 == big)
rows = np.where(board.any(1))[0]; cols = np.where(board.any(0))[0]
# the plate is the wide part: rows where the board spans more than 60% of its width (posts are narrow)
wide = [y for y in rows if board[y].sum() > 0.6 * (cols[-1] - cols[0])]; y0, y1 = wide[0], wide[-1]
x0, x1 = cols[0], cols[-1]
orig = np.asarray(im).astype(float); plate = orig.copy()
# clean texture: a strip just inside the left edge of the plate (no print there), mirrored across the interior, then shaded
# left to right toward a clean strip on the right edge (the plate darkens to the right) and feathered into the original
inset = int(0.035 * (x1 - x0)); sx0 = x0 + inset; sw = int(0.04 * (x1 - x0))
strip = orig[:, sx0:sx0 + sw].copy()
ix0, ix1 = x0 + inset, x1 - inset; iy0, iy1 = y0 + int(inset * .55), y1 - inset
fill = np.zeros((iy1 - iy0, ix1 - ix0, 3)); x = 0; flip = False
while x < ix1 - ix0:
wpart = min(sw, ix1 - ix0 - x); part = strip[iy0:iy1, :wpart] if not flip else strip[iy0:iy1, ::-1][:, :wpart]
fill[:, x:x + wpart] = part; x += wpart; flip = not flip
lm = strip[iy0:iy1].mean((1, 2)); rm = orig[iy0:iy1, ix1 - sw:ix1].mean((1, 2))
lm = nd.uniform_filter1d(lm, 61); rm = nd.uniform_filter1d(rm, 61)
t = np.linspace(0, 1, ix1 - ix0)[None, :]; ratio = (1 + t * (rm / np.maximum(lm, 1) - 1)[:, None])[..., None]
fill = fill * ratio
m = np.zeros(L.shape); m[iy0:iy1, ix0:ix1] = 1; m = nd.gaussian_filter(m, 4)[iy0:iy1, ix0:ix1][..., None]
plate[iy0:iy1, ix0:ix1] = fill * m + orig[iy0:iy1, ix0:ix1] * (1 - m)
plate = np.clip(plate, 0, 255).astype('uint8')
alpha = Image.fromarray((board * 255).astype('uint8')).filter(ImageFilter.GaussianBlur(1.2))
pl = Image.fromarray(plate); pl.putalpha(alpha); pl = pl.crop((x0 - 4, y0 - 4, x1 + 5, y1 + 5))
# the Draft Day card wants a wide, short panel (900 x 210): drop rows from the plate's uniform middle instead of squashing it
th = int(210 * pl.width / 900); keep = th // 2
pl = Image.fromarray(np.concatenate([np.asarray(pl)[:keep], np.asarray(pl)[-(th - keep):]]))
save_png(pl.resize((900, 210), Image.LANCZOS), os.path.join(DD, 'scoreboard.png'), 96)
# 9. Champiun (T3, DikasStudio) Bold, subset to Basic Latin, WOFF (only the "ON THE CLOCK" headline and pick numbers use it)
from fontTools import subset
from fontTools.ttLib import TTFont
f = TTFont(one('T3', 'Champiun-Bold.ttf'))
sub = subset.Subsetter(subset.Options(layout_features=['kern', 'liga'], flavor='woff', desubroutinize=True))
sub.populate(unicodes=list(range(0x20, 0x7f)) + [0x2019, 0xb7]); sub.subset(f)
f.flavor = 'woff'; fp = os.path.join(APP, 'public', 'assets', 'champiun.woff'); f.save(fp); print('public/assets/champiun.woff', os.path.getsize(fp) // 1024, 'KB')