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)

# ===========================================================
# APPROACH: Standard split-face — BOTH halves face the viewer.
#
# A person facing camera:
#   Their anatomical LEFT is on image RIGHT of centerline.
#   We take image-RIGHT half (their left face) from BOTH subjects.
#   This half naturally faces toward the viewer.
#   We mirror/flip it so it goes on the LEFT side of the composite
#   but still faces right toward the viewer (same as a true left face half).
#
# Wait — actually let me just take both anatomical left face halves
# (image right of centerline), and place them side by side.
# Both will face toward the viewer. The seam is in the middle.
# ===========================================================

# Take man's left face half (image RIGHT of his centerline)
m_left = man.crop((man_cx, 220, min(man.width, man_cx + 280), 930))
# Take woman's left face half (image RIGHT of her centerline)  
w_left = woman.crop((woman_cx, 80, woman_cx + 280, 740))

# Build composite: flip the first half so both face the viewer from their respective sides
m_l = fit_h(m_left, TARGET_H)
w_l = fit_h(w_left, TARGET_H)

# For a balanced split-face: mirror the man's half so it sits on the LEFT and faces right
# (as if it's his anatomical right face half from a mirrored view)
m_l_mirrored = m_l.transpose(Image.FLIP_LEFT_RIGHT)

# Version A: Man on LEFT, Woman on RIGHT
vA = Image.new('RGB', (m_l_mirrored.width + w_l.width, TARGET_H), (30, 30, 30))
vA.paste(m_l_mirrored, (0, 0))
vA.paste(w_l, (m_l_mirrored.width, 0))
vA.save('/root/workspace/split_headshot_A.jpg', quality=95)

# Version B: Woman on LEFT, Man on RIGHT
w_l_mirrored = w_l.transpose(Image.FLIP_LEFT_RIGHT)
vB = Image.new('RGB', (w_l_mirrored.width + m_l.width, TARGET_H), (30, 30, 30))
vB.paste(w_l_mirrored, (0, 0))
vB.paste(m_l, (w_l_mirrored.width, 0))
vB.save('/root/workspace/split_headshot_B.jpg', quality=95)

print(f'A: {vA.size}  |  B: {vB.size}')
print(f'A: man(flipped)={m_l_mirrored.size} woman={w_l.size}')
print(f'B: woman(flipped)={w_l_mirrored.size} man={m_l.size}')
