from PIL import Image

SRC = '/root/.hermes/webui/attachments/9710c799d486/'
man = Image.open(SRC + '707f2402-9eb3-4aa0-a58b-fbb46d61815f.jpg').crop((0, 250, 946, 1180))
woman = Image.open(SRC + 'e461f313-7e7d-4183-93b2-f3d0e9756d73.jpg').crop((0, 250, 946, 1180))

# Face centerlines (source coords within the 946x930 crops)
man_cx, woman_cx = 730, 512

# man: right half of his face (image-left of centerline), woman: left half of hers
man_half = man.crop((man_cx - 250, 220, man_cx, 930))
woman_half = woman.crop((woman_cx, 80, woman_cx + 250, 740))

TARGET_H = 960

def fit_to_h(im, h):
    w = round(im.width * h / im.height)
    return im.resize((w, h), Image.LANCZOS)

mh = fit_to_h(man_half, TARGET_H)
wh = fit_to_h(woman_half, TARGET_H)

out = Image.new('RGB', (mh.width + wh.width, TARGET_H), (0, 0, 0))
out.paste(mh, (0, 0))
out.paste(wh, (mh.width, 0))
out.save('/root/workspace/split_headshot.jpg', quality=95)
print('size', out.size, 'man half', mh.size, 'woman half', wh.size)