#!/usr/bin/env python3
from pathlib import Path
import base64,json,struct,urllib.request
P=Path(__file__).resolve().parents[1];out=P/'images/intro_poster.png';assert not out.exists()
ENV=Path('/home/hermes/.hermes/skills/image-generation/gen-img-gpt/references/.env');URL='http://192.168.40.11:20128/v1/images/generations'
k=next(line.split('=',1)[1].strip().strip('"\'') for line in ENV.read_text().splitlines() if '=' in line and line.split('=',1)[1].strip())
prompt='Classic stick-figure doodle on a light cream whiteboard-like background, simple black lines with slightly imperfect natural hand-drawn character. High-impact stop-scroll mobile thumbnail. Large distressed stick figure has just stood from a chair, grips a table, blacked-out eyes and sweat show sudden dim vision. Strong causal metaphor: blue upward path to brain is interrupted while red blood droplets and gravity arrows pool toward legs. Foreground furniture cropped intentionally, expressive face large, bold orange-black-blue hierarchy, three purposeful layers, no dead space. Display exactly one readable Vietnamese headline, including the comma and question mark: “VỪA ĐỨNG DẬY, MẮT BỖNG TỐI SẦM?” Do not display any other readable word, logo, signature, watermark, or pseudo-text. 16:9.'
body={'model':'cx/gpt-5.5-image','prompt':prompt,'size':'1536x1024','response_format':'b64_json'};req=urllib.request.Request(URL,data=json.dumps(body).encode(),headers={'Authorization':'Bearer '+k,'Content-Type':'application/json'},method='POST');tmp=out.with_suffix('.repair.tmp.png');tmp.write_bytes(base64.b64decode(json.load(urllib.request.urlopen(req,timeout=1200))['data'][0]['b64_json']));d=tmp.read_bytes();w,h=struct.unpack('>II',d[16:24]);assert len(d)>10000 and d[:8]==b'\x89PNG\r\n\x1a\n' and d[-8:-4]==b'IEND' and w>=1024 and h>=576;tmp.replace(out);print('POSTER_REPAIR PASS')
