28 lines
1.7 KiB
Python
28 lines
1.7 KiB
Python
# 라이트 템플릿용 썸네일 — 세로 화면을 카드(3.03:1)·표지 격자(16:9) 비율로 잘라낸다
|
|
import os
|
|
from PIL import Image
|
|
BASE = r"E:\BurningTimes\공유\기획\FirstRising"
|
|
TB = lambda n: os.path.join(BASE, "레퍼런스_TBH", "img", n)
|
|
OUT = os.path.join(BASE, "리뉴얼", "img")
|
|
|
|
def crop(src, box, name, maxw=1400):
|
|
im = Image.open(src).convert("RGB").crop(box)
|
|
if im.width > maxw:
|
|
im = im.resize((maxw, int(im.height * maxw / im.width)), Image.LANCZOS)
|
|
im.save(os.path.join(OUT, name), quality=90); print(name, im.size)
|
|
|
|
def ar_box(w, h, ratio, cx=None, cy=None):
|
|
"""(w,h) 이미지에서 비율 ratio(가로/세로)로 가장 큰 상자, 중심 cx·cy(비율)"""
|
|
cx = 0.5 if cx is None else cx; cy = 0.5 if cy is None else cy
|
|
if w / h > ratio:
|
|
nw = int(h * ratio); x0 = int(min(max(w * cx - nw / 2, 0), w - nw)); return (x0, 0, x0 + nw, h)
|
|
nh = int(w / ratio); y0 = int(min(max(h * cy - nh / 2, 0), h - nh)); return (0, y0, w, y0 + nh)
|
|
|
|
strip = Image.open(TB("02_taskbar_strip.jpg")); hero = Image.open(TB("03_hero_panel.jpg")); trade = Image.open(TB("09_trade_ship.jpg")); rune = Image.open(TB("07_rune_tree.jpg"))
|
|
crop(TB("02_taskbar_strip.jpg"), ar_box(*strip.size, 3.03, cx=0.52), "thumb_strip.jpg")
|
|
crop(TB("03_hero_panel.jpg"), ar_box(*hero.size, 3.03, cy=0.26), "thumb_hero.jpg")
|
|
crop(TB("09_trade_ship.jpg"), ar_box(*trade.size, 3.03, cy=0.14), "thumb_trade.jpg")
|
|
crop(TB("03_hero_panel.jpg"), ar_box(*hero.size, 16 / 9, cy=0.34), "cover_hero.jpg")
|
|
crop(TB("09_trade_ship.jpg"), ar_box(*trade.size, 16 / 9, cy=0.3), "cover_trade.jpg")
|
|
crop(TB("07_rune_tree.jpg"), ar_box(*rune.size, 16 / 9, cx=0.45), "cover_rune.jpg")
|