가사 데이터 보강(활약·타율) + 커버는 팀 로고 100%

- 전날 경기 활약: KBO=네이버 record 타자 boxscore(홈런·3안타 이상),
  MLB=boxscore batting — 어제 결과 줄에 "활약: ..." 로 부가
- 확정 라인업에 타자 시즌 타율 병기 (MLB=seasonStats, KBO=최근 경기 hra 맵)
- 커버 합성에서 Suno 배경 제거 — 다크 단색 배경 + 팀 로고 최대 크기

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
JinwooKimandClaude Fable 5 committed 2026-08-25 10:42:55 +09:00
1 parent c895bc9c6b
commit abcdf42aeb
2 files changed
+135 -49

No files matched your search

+10 -22
View File
@@ -73,31 +73,21 @@ def _logo_url(s: Song) -> str | None:
return None
def _compose(bg_bytes: bytes | None, logo_bytes: bytes | None) -> bytes:
def _compose(logo_bytes: bytes | None) -> bytes:
"""다크 단색 배경 + 팀 로고 최대 크기 중앙 배치 (배경 아트 없음)."""
import io
from PIL import Image, ImageEnhance
from PIL import Image
canvas = Image.new("RGB", (_COVER_W, _COVER_H), (16, 20, 26))
if bg_bytes:
try:
bg = Image.open(io.BytesIO(bg_bytes)).convert("RGB")
# cover-crop: 비율 유지 확대 후 중앙 크롭
scale = max(_COVER_W / bg.width, _COVER_H / bg.height)
bg = bg.resize((round(bg.width * scale), round(bg.height * scale)))
x = (bg.width - _COVER_W) // 2
y = (bg.height - _COVER_H) // 2
bg = bg.crop((x, y, x + _COVER_W, y + _COVER_H))
canvas = ImageEnhance.Brightness(bg).enhance(0.5) # 로고 대비용 감광
except Exception as e: # noqa: BLE001
log.warning("cover 배경 처리 실패: %s", e)
if logo_bytes:
try:
logo = Image.open(io.BytesIO(logo_bytes)).convert("RGBA")
h = 340
w = round(logo.width * h / logo.height)
if w > 560:
w, h = 560, round(logo.height * 560 / logo.width)
# 캔버스에 여백 8%만 남기고 최대로 채운다
max_h = round(_COVER_H * 0.84)
max_w = round(_COVER_W * 0.84)
scale = min(max_w / logo.width, max_h / logo.height)
w, h = round(logo.width * scale), round(logo.height * scale)
logo = logo.resize((w, h))
canvas.paste(logo, ((_COVER_W - w) // 2, (_COVER_H - h) // 2), logo)
except Exception as e: # noqa: BLE001
@@ -118,15 +108,13 @@ async def song_cover(
).scalar_one_or_none()
if not s:
raise HTTPException(status_code=404, detail="SONG_NOT_FOUND")
key = f"{match_id}:{team_code}:{s.task_id}"
key = f"{match_id}:{team_code}"
if key not in _cover_cache:
if len(_cover_cache) > 200:
_cover_cache.clear()
suno_img = ((s.tracks or [{}])[0] or {}).get("imageUrl") or ""
bg = await _fetch_bytes(suno_img) if suno_img.startswith("http") else None
logo_url = _logo_url(s)
logo = await _fetch_bytes(logo_url) if logo_url else None
_cover_cache[key] = _compose(bg, logo)
_cover_cache[key] = _compose(logo)
return Response(
content=_cover_cache[key],
media_type="image/jpeg",