Use bluearchive.wiki portraits for gacha cards

This commit is contained in:
esef committed 2026-09-15 16:35:04 +03:00
1 parent e4b5f0d849
commit c510a1b63f
3 files changed
+47 -19

No files matched your search

+16 -18
View File
@@ -48,25 +48,23 @@ FOOTER_FONT = _get_font(18, bold=False)
# ── Image fetching ─────────────────────────────────────────────────────────
async def _fetch_portrait(session: aiohttp.ClientSession, student: dict) -> Optional[Image.Image]:
"""Download a student's full-body portrait and crop it to the card area.
Portraits come from the SchaleDB image CDN, keyed by student ID.
"""
url = db.cdn_portrait(student)
try:
async with session.get(url, timeout=aiohttp.ClientTimeout(total=5)) as resp:
if resp.status == 200:
data = await resp.read()
img = Image.open(io.BytesIO(data)).convert("RGBA")
# Full-body art; crop the upper portion to fit the card.
p_w, p_h = img.size
crop_h = int(p_w * 1.20)
if crop_h < p_h:
img = img.crop((0, 0, p_w, crop_h))
return img
except Exception:
log.exception("Failed to fetch portrait for %s", student["Name"])
"""Download a student's portrait (wiki bust art first, full sprite fallback)."""
for url in (db.cdn_portrait(student), db.cdn_sprite(student)):
try:
async with session.get(url, timeout=aiohttp.ClientTimeout(total=5)) as resp:
if resp.status == 200:
data = await resp.read()
img = Image.open(io.BytesIO(data)).convert("RGBA")
# Full-body art is tall; crop the upper portion to fit the card.
p_w, p_h = img.size
crop_h = int(p_w * 1.20)
if crop_h < p_h:
img = img.crop((0, 0, p_w, crop_h))
return img
except Exception:
log.debug("portrait fetch failed via %s", url)
log.warning("no portrait for %s", student["Name"])
return None