import os,sys,json,hashlib
from pathlib import Path

def load_env(path):
    for line in Path(path).read_text(errors='ignore').splitlines():
        line=line.strip()
        if not line or line.startswith('#') or '=' not in line: continue
        k,v=line.split('=',1);os.environ.setdefault(k.strip(),v.strip().strip('"\''))
load_env('/opt/OpenMontage/.env');sys.path.insert(0,'/opt/OpenMontage')
from tools.graphics.cx_image import CXImage
P='gacmai_20260718_075153';R=Path('/data/video-pipeline/GacMaiAudio/project')/P;I=R/'assets/images';I.mkdir(parents=True,exist_ok=True)
SYSTEM=('A commissioned Vietnamese cinematic audio-drama film-poster campaign for ĐƯỜNG NƯỚC TRỞ VỀ. Premium semi-realistic painterly illustration, unmistakable theatrical key art rather than a scenic illustration: dramatic amber key light and teal rim shadows, deep foreground/midground/background staging, volumetric river mist, controlled visual hierarchy, antique-gold editorial typography, serious emotional tension, cohesive faces/costumes/palette across all assets. No photography, no plastic 3D, no flat clip-art, no UI screenshot, no watermark, no pseudo-text, no extra logos or seals. ')
jobs=[
 ('intro_campaign_native_rev2.png','1920x1080',SYSTEM+'Native 16:9 theatrical opening poster. EXACTLY six Vietnamese adults total, exactly three women and three men, no background humans. Female land-records specialist Võ Thanh Hà is the dominant largest center-front protagonist. Five supporting adults behind her, all full faces visible. Floodplain after receding water, embankment stakes, empty communal passage, blank cloth map with no markings. Exact readable text only: ĐƯỜNG NƯỚC TRỞ VỀ ; Gác Mái Audio ; Truyện độc quyền, nghiêm cấm sao chép dưới mọi hình thức. Mandatory comma after quyền; no terminal punctuation after thức.'),
 ('left_campaign_native_rev2.png','1080x1920',SYSTEM+'NATIVE 9:16 PORTRAIT left rail poster, composed vertically from the start, full-bleed edge-to-edge portrait artwork with no landscape card, no top/bottom letterbox, no people. Dramatic vertical river reeds, floodplain path, survey stakes, mist and sunset light creating theatrical depth. Strong vertical typographic hierarchy. Exact readable text only: Gác Mái Audio ; Like ; Share ; Subscribe. No other words. This must be a true portrait film-poster panel, not a 16:9 image placed inside a tall canvas.'),
 ('right_campaign_native_rev2.png','1080x1920',SYSTEM+'NATIVE 9:16 PORTRAIT ensemble film poster, composed vertically from the start, full-bleed edge-to-edge portrait artwork with no landscape card, no top/bottom letterbox. EXACTLY six Vietnamese adults total, exactly three women and three men, no background humans. Female Võ Thanh Hà is dominant and largest in the vertical center; five supporting adults arranged in layered theatrical portrait composition, all full faces visible. Floodplain and amber-teal atmosphere. Exact readable text only: ĐƯỜNG NƯỚC TRỞ VỀ. No names, credits or other text. This must be a true portrait key-art panel.')]
provider=CXImage();results=[]
for name,size,prompt in jobs:
 out=I/name;r=provider.execute({'prompt':prompt,'model':'cx/gpt-5.5-image','size':size,'quality':'high','background':'auto','image_detail':'high','output_format':'png','n':1,'output_path':str(out)})
 if not r.success:raise SystemExit(f'{name}: {r.error}')
 results.append({'file':str(out),'size_requested':size,'sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'provider':r.data.get('provider'),'model':r.model})
print(json.dumps({'status':'passed','results':results},ensure_ascii=False))
