File size: 2,245 Bytes
f424be1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Normalize raw TCG card images to 896x1200 JPG and WebP in assets/cards/."""
import os
import shutil
from pathlib import Path
from PIL import Image

NAME_MAP = {
    '亞歷山大': 'alexander',
    '伊麗莎白': 'elizabeth',
    '岳飛': 'yuefei',
    '劉銘傳': 'liumingchuan',
    '李鴻章': 'lihongzhang',
    '戚繼光': 'qijiguang',
    '施琅': 'shilang',
    '樺山資紀': 'kabayamasukenori',
    '趙匡胤': 'zhaokuangyin',
    '秋瑾': 'qiujin',
    '鄭成功': 'zhengchenggong',
    '劉永福': 'liuyongfu',
    '拿破崙': 'napoleon',
    '俾斯麥': 'bismarck',
    '貞德': 'jeanne',
}

TIERS = ['SSR', 'SR', 'R', 'C']


def normalize_one(src_path: Path, hero_id: str, tier: str, out_dir: Path):
    """Resize src_path to 896x1200 and save JPG + WebP."""
    im = Image.open(src_path).convert('RGB')
    if im.size != (896, 1200):
        im = im.resize((896, 1200), Image.Resampling.LANCZOS)

    base = f'tcg_{hero_id}_{tier.lower()}'
    jpg_out = out_dir / f'{base}.jpg'
    webp_out = out_dir / f'{base}.webp'

    im.save(jpg_out, format='JPEG', quality=92, optimize=True)
    im.save(webp_out, format='WEBP', quality=85, method=6)
    print(f'Normalized {src_path.name} -> {jpg_out.name} ({jpg_out.stat().st_size // 1024}KB), {webp_out.name} ({webp_out.stat().st_size // 1024}KB)')


def main():
    raw_dir = Path('assets/cards/1')
    out_dir = Path('assets/cards')
    done_dir = Path('assets/cards/_raw_done')
    if not raw_dir.exists():
        print('No raw_dir found.')
        return

    done_dir.mkdir(parents=True, exist_ok=True)
    for f in sorted(raw_dir.iterdir()):
        if not f.is_file() or f.suffix.lower() not in ('.jpg', '.jpeg', '.png', '.webp'):
            continue
        stem = f.stem
        matched = False
        for zh, hid in NAME_MAP.items():
            if stem.startswith(zh):
                rest = stem[len(zh):].upper()
                if rest in TIERS:
                    normalize_one(f, hid, rest, out_dir)
                    shutil.move(str(f), str(done_dir / f.name))
                    matched = True
                    break
        if not matched:
            print(f'Skipped unrecognized filename: {f.name}')


if __name__ == '__main__':
    main()