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

# Centers in 946x930 images
man_cx = 730   # man's face is on the right side of the image
woman_cx = 512 # woman's face is near the center

TARGET_H = 960
HW = 280       # half-face width

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

# ===========================================================
# STRATEGY: Take anatomical LEFT face half from each person
# (image RIGHT of centerline — e.g. his left eye, left cheek, left ear)
# Both halves face the viewer naturally.
#
# Version A: Man on LEFT side of composite, Woman on RIGHT
#   - Man's left face half → FLIP horizontally → places on LEFT, still faces viewer
#   - Woman's left face half → stays as-is → places on RIGHT, faces viewer
#
# Version B: Woman on LEFT, Man on RIGHT
#   - Woman's left face half → FLIP → places on LEFT, faces viewer
#   - Man's left face half → stays → places on RIGHT, faces viewer
# ===========================================================

# --- VERSION A ---
m_left_face = man.crop((man_cx, 220, min(man.width, man_cx + HW), 930))
w_left_face = woman.crop((woman_cx, 80, woman_cx + HW, 740))

m_l = fit_h(m_left_face, TARGET_H)
w_l = fit_h(w_left_face, TARGET_H)

# Flip man's half so it goes on LEFT side facing viewer
m_l_flipped = m_l.transpose(Image.FLIP_LEFT_RIGHT)

vA = Image.new('RGB', (m_l_flipped.width + w_l.width, TARGET_H), (30, 30, 30))
vA.paste(m_l_flipped, (0, 0))
vA.paste(w_l, (m_l_flipped.width, 0))
vA.save('/root/workspace/split_headshot_A.jpg', quality=95)

# --- VERSION B ---
w_lf = fit_h(w_left_face, TARGET_H)
m_lf = fit_h(m_left_face, TARGET_H)

w_lf_flipped = w_lf.transpose(Image.FLIP_LEFT_RIGHT)

vB = Image.new('RGB', (w_lf_flipped.width + m_lf.width, TARGET_H), (30, 30, 30))
vB.paste(w_lf_flipped, (0, 0))
vB.paste(m_lf, (w_lf_flipped.width, 0))
vB.save('/root/workspace/split_headshot_B.jpg', quality=95)

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