"""
Prep final: foto_20 (fachada entardecer) com tratamento minimo — ja tem atmosfera pronta.
Apenas leve darken uniforme na parte central onde o overlay verde vai entrar,
pra garantir contraste do texto sem estragar a foto.
"""
from PIL import Image, ImageEnhance, ImageFilter, ImageDraw

SRC = "/opt/mia/workspace/clientes/chacara-sonho-verde/fotos_originais/foto_20_treated.jpg"
OUT = "/opt/mia/workspace/clientes/chacara-sonho-verde/refs_video/build/foto_bg_final.jpg"

img = Image.open(SRC).convert("RGB")
w, h = img.size

# crop 4:5 centralizado
target_ratio = 4/5
current_ratio = w/h
if current_ratio > target_ratio:
    new_w = int(h * target_ratio)
    left = (w - new_w) // 2
    img = img.crop((left, 0, left + new_w, h))
else:
    new_h = int(w / target_ratio)
    top = (h - new_h) // 2
    img = img.crop((0, top, w, top + new_h))

img = img.resize((1280, 1600), Image.LANCZOS)

# tratamento sutil — mantendo mood original
img = ImageEnhance.Contrast(img).enhance(1.08)
img = ImageEnhance.Color(img).enhance(1.15)
img = ImageEnhance.Brightness(img).enhance(0.92)

img.save(OUT, quality=94)
print(f"salvo: {OUT}")
