Files
linkspin/tools/niche-heroes-pack.py

36 lines
1.8 KiB
Python

# Pack the niche hero sets: originals (-1) + generated (-2..-4, gaming -1..-4) -> optimized JPEGs in the LinkSpin repo,
# plus a contact sheet for review.
from PIL import Image, ImageDraw
import os, pathlib
HERE = pathlib.Path(__file__).parent; OUT = pathlib.Path('D:/Projects/HighRisk/linkspin/site/public/niches'); OUT.mkdir(exist_ok=True)
NICHES = ['health-wellness', 'make-money-online', 'personal-finance', 'coaching-consulting', 'self-improvement', 'relationships', 'gaming']
rows = []
for n in NICHES:
files = []
if n != 'gaming': files.append(HERE / f'{n}.jpg')
for i in range(1, 5):
p = HERE / 'gen' / f'{n}-{i}.png'
if p.exists(): files.append(p)
files = files[:4]
row = []
for i, src in enumerate(files):
im = Image.open(src).convert('RGB')
if im.size != (1536, 1024): im = im.resize((1536, 1024), Image.LANCZOS)
dst = OUT / f'{n}-{i + 1}.jpg'
im.save(dst, 'JPEG', quality=82, optimize=True, progressive=True)
row.append((dst.name, im.copy(), os.path.getsize(dst) // 1024))
rows.append((n, row))
# contact sheet: 4 across, one row per niche
TW, TH, PAD, LAB = 384, 256, 10, 26
sheet = Image.new('RGB', (4 * (TW + PAD) + PAD, len(rows) * (TH + LAB + PAD) + PAD), (18, 18, 22)); d = ImageDraw.Draw(sheet)
for r, (n, row) in enumerate(rows):
y = PAD + r * (TH + LAB + PAD)
d.text((PAD, y + 4), n.upper(), fill=(230, 230, 235))
for c, (name, im, kb) in enumerate(row):
x = PAD + c * (TW + PAD)
sheet.paste(im.resize((TW, TH), Image.LANCZOS), (x, y + LAB))
d.text((x + 6, y + LAB + TH - 18), f'{name} {kb}KB', fill=(255, 255, 255))
sheet.save(HERE / 'contact-sheet.jpg', 'JPEG', quality=80)
for n, row in rows: print(n, [(a, c) for a, _, c in row])
print('total KB', sum(os.path.getsize(OUT / f) for f in os.listdir(OUT)) // 1024)