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
HW = 280

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

# --- VERSION A: Man LEFT, Woman RIGHT ---
# Man's right face half: image LEFT of his centerline (faces right, toward center seam)
m_right = man.crop((man_cx - HW, 220, man_cx, 930))
# Woman's left face half: image RIGHT of her centerline (faces left, toward center seam)
w_left = woman.crop((woman_cx, 80, woman_cx + HW, 740))

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 LEFT, Man RIGHT ---
# Woman's right face half: image LEFT of her centerline (faces right, toward center seam)
w_right = woman.crop((woman_cx - HW, 80, woman_cx, 740))
# Man's left face half: image RIGHT of his centerline (faces left, toward center seam)
m_left = man.crop((man_cx, 220, man_cx + HW, 930))

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