39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""아이콘 PNG 옆에 웹용 WebP 사본을 만든다. 아이콘을 추가하거나 바꾼 뒤 실행한다.
|
|
|
|
python frontend/scripts/icons_webp.py
|
|
|
|
웹은 WebP 를 쓰고(frontend/src/b/lib.ts iconSrc), PNG 원본은 앱·admin 카드가 그대로 쓴다.
|
|
PNG 보다 새 WebP 가 이미 있으면 건너뛴다. Pillow 가 필요하다 (backend 와 같은 패키지).
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
PUBLIC = Path(__file__).resolve().parent.parent / "public"
|
|
DIRS = [PUBLIC / "icons", PUBLIC / "b" / "icons"]
|
|
# 아이콘은 256px 정사각형. 그보다 큰 그림(원본·로고)은 아이콘이 아니라 건너뛴다
|
|
MAX_SIDE = 256
|
|
QUALITY = 85
|
|
|
|
|
|
def main() -> None:
|
|
made = 0
|
|
for folder in DIRS:
|
|
for png in sorted(folder.glob("*.png")):
|
|
webp = png.with_suffix(".webp")
|
|
if webp.exists() and webp.stat().st_mtime >= png.stat().st_mtime:
|
|
continue
|
|
with Image.open(png) as im:
|
|
if max(im.size) > MAX_SIDE:
|
|
print(f"건너뜀 (아이콘 크기 아님 {im.size[0]}x{im.size[1]}): {png.name}")
|
|
continue
|
|
im.convert("RGBA").save(webp, "WEBP", quality=QUALITY, method=6)
|
|
made += 1
|
|
print(f"{png.name}: {png.stat().st_size // 1024}KB -> {webp.stat().st_size // 1024}KB")
|
|
print(f"WebP {made}개 만듦")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|