Files

40 lines
1.9 KiB
Python

"""16:9 versions of the 4:3-displayed square loading screens, without inventing detail.
Centre: the screen at 4:3. Sides: mirrored edge strips. Framed screens keep the parchment
frame bands sharp (the frame is an ornamental horizontal band), and only the picture strip
between them is blurred and darkened toward the outside. Full-art screens blur the whole side."""
import sys
from PIL import Image, ImageFilter, ImageOps
import numpy as np
from bands import bands
FULL_ART = {'loadscreeneasternkingdom','loadscreenkalimdor','131820','131861','8537134','8537149','8537152','131831','131843'}
DEFAULT = (0.18, 0.19)
def wide(src, name, H=1080):
W43, W = H*4//3, H*16//9
c = src.convert('RGB').resize((W43, H), Image.LANCZOS)
side = (W-W43)//2
if name in FULL_ART: t, b = 0.0, 0.0
else:
t, b = bands(src)
t = t if 0.10 <= t <= 0.22 else DEFAULT[0]; b = b if 0.10 <= b <= 0.22 else DEFAULT[1]
top, bot = int(t*H), int(b*H)
out = Image.new('RGB', (W, H))
for x0, x1, dst, flip in ((0, side, 0, False), (W43-side, W43, side+W43, True)):
strip = ImageOps.mirror(c.crop((x0, 0, x1, H)))
blurred = np.asarray(strip.filter(ImageFilter.GaussianBlur(28)), float)
ramp = np.linspace(0.35, 0.85, side)[None, :, None]
if flip: ramp = ramp[:, ::-1]
a = blurred*ramp
sharp = np.asarray(strip, float)
# sharp frame bands, feathered 24 px into the blurred picture strip
w = np.zeros(H)
if top: w[:top] = 1; w[top:top+24] = np.linspace(1, 0, 24)
if bot: w[H-bot:] = 1; w[H-bot-24:H-bot] = np.linspace(0, 1, 24)
w = w[:, None, None]
a = a*(1-w) + sharp*w
out.paste(Image.fromarray(a.clip(0,255).astype('uint8')), (dst, 0))
out.paste(c, (side, 0))
return out
if __name__ == '__main__':
import os
wide(Image.open(sys.argv[1]), os.path.basename(sys.argv[1])[:-4]).save(sys.argv[2])