"""A wide mission control behind the Director, for the trailer's close-ups, put together from the pieces of the upright T_Dir_Bg: the wall in bands, the ceiling lamps, bunting and desks repeated, the banner, the monitor and the window placed along it.""" import sys import numpy as np from PIL import Image, ImageFilter src = Image.open(sys.argv[1]).convert("RGB") out = sys.argv[2] w, h = src.size a = np.asarray(src).astype(np.float32) W = int(h * 16 / 9) # the wall in bands: each row's colour where nothing hangs (the strip between the banner and the window) plain = a[:, 300:318].mean(axis=1) canvas = np.repeat(plain[:, None, :], W, axis=1) img = Image.fromarray(canvas.clip(0, 255).astype(np.uint8)) def crop(x0, y0, x1, y1): return src.crop((x0, y0, x1, y1)) def tile(piece, y, step, start=0): for x in range(start, W, step): img.paste(piece, (x, y)) # ceiling lamps, bunting, desks lamp = crop(360, 160, 452, 248) tile(lamp, 160, 330, 30) bunting = crop(320, 290, 720, 340) tile(bunting, 290, 400) desks = crop(0, 680, 700, 840) tile(desks, 680, 700, 20) floor = crop(0, 840, 700, h) tile(floor, 840, 700, 20) # the monitor, whole: its right half and that half mirrored half = crop(0, 335, 118, 650) mon = Image.new("RGB", (236, 315)) mon.paste(half.transpose(Image.FLIP_LEFT_RIGHT), (0, 0)) mon.paste(half, (118, 0)) banner = crop(128, 300, 312, 605) window = crop(320, 330, 720, 662) # the window's right frame, cut off in the strip: its left frame drawn again on the right frame = crop(320, 330, 344, 662) win = Image.new("RGB", (424, 332)) win.paste(window, (0, 0)) win.paste(frame, (400, 0)) cx = W // 2 img.paste(win, (cx - 212, 330)) img.paste(banner, (cx - 212 - 60 - 184, 300)) img.paste(banner, (cx + 212 + 60, 300)) img.paste(mon, (cx - 212 - 60 - 184 - 70 - 236, 335)) img.paste(mon, (cx + 212 + 60 + 184 + 70, 335)) img.paste(win, (cx - 212 - 60 - 184 - 70 - 236 - 70 - 424, 330)) img.paste(win.transpose(Image.FLIP_LEFT_RIGHT), (cx + 212 + 60 + 184 + 70 + 236 + 70, 330)) img = img.filter(ImageFilter.GaussianBlur(1.5)) img.save(out) print(img.size)