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))

man_cx = 730
woman_cx = 512
TARGET_H = 960

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

# Crop half-faces
m_right = man.crop((man_cx - 280, 220, man_cx, 930))  # man's anatomical right, faces right/toward-center
w_left  = woman.crop((woman_cx, 80, woman_cx + 280, 740))  # woman's anatomical left, faces left/toward-center

vA_l = fit_h(m_right, TARGET_H)
vA_r = fit_h(w_left, TARGET_H)
vA = Image.new('RGB', (vA_l.width + vA_r.width, TARGET_H), (20, 20, 20))
vA.paste(vA_l, (0, 0))
vA.paste(vA_r, (vA_l.width, 0))
vA.save('/root/workspace/split_headshot_A.jpg', quality=95)

# Version B: woman's right half on left, man's left half on right
w_right = woman.crop((woman_cx - 280, 80, woman_cx, 740))  # woman's anatomical right, faces right
m_left  = man.crop((man_cx, 220, man_cx + 280, 930))        # man's anatomical left, faces left

vB_l = fit_h(w_right, TARGET_H)
vB_r = fit_h(m_left, TARGET_H)
vB = Image.new('RGB', (vB_l.width + vB_r.width, TARGET_H), (20, 20, 20))
vB.paste(vB_l, (0, 0))
vB.paste(vB_r, (vB_l.width, 0))
vB.save('/root/workspace/split_headshot_B.jpg', quality=95)

print(f'A: {vA.size}  |  B: {vB.size}')
