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)

# Take each person's anatomical RIGHT face half (image LEFT of their centerline)
# These naturally face toward the right/viewer — a proper split-face look.

m_right = man.crop((man_cx - 280, 220, man_cx, 930))
w_right = woman.crop((woman_cx - 280, 80, woman_cx, 740))

m_r = fit_h(m_right, TARGET_H)
w_r = fit_h(w_right, TARGET_H)

# Version A: man LEFT, woman RIGHT
vA = Image.new('RGB', (m_r.width + w_r.width, TARGET_H), (30, 30, 30))
vA.paste(m_r, (0, 0))
vA.paste(w_r, (m_r.width, 0))
vA.save('/root/workspace/split_headshot_A.jpg', quality=95)

# Version B: woman LEFT, man RIGHT
vB = Image.new('RGB', (w_r.width + m_r.width, TARGET_H), (30, 30, 30))
vB.paste(w_r, (0, 0))
vB.paste(m_r, (w_r.width, 0))
vB.save('/root/workspace/split_headshot_B.jpg', quality=95)

print(f'A: {vA.size} | B: {vB.size}')
print('A: man-right-half | woman-right-half')
print('B: woman-right-half | man-right-half')
