Image Request & Annotation
Request Flow
image.RequestImage steps:
- Build
prompt.Requestwith model (currentlydall-e-3). - Infer size from orientation keywords (landscape/horizontal/vertical) else square.
- Early placeholder file if
OPENAI_API_KEYmissing. - POST to OpenAI images endpoint (override via baseURL parameter upstream).
- Parse response: URL path OR base64 fallback (
b64_json). - Download or decode → write
generated/<file>.png. - Annotate with terse prompt via
annotate.Annotate→ writeannotated/<file>.png. - Update progress phases (wait → download → annotate) and DalleDress fields (ImageURL, DownloadMode, paths).
Download Modes
urldirect HTTP GETb64inline base64 decode (when no URL provided)
Annotation Mechanics
annotate.Annotate:
- Validates source path contains
/generated/ - Reads image, computes dominant colors (top 3 frequency) → average background
- Chooses contrasting text (white/black) via lightness threshold
- Draws separator line + wraps caption text
- Writes sibling file swapping
generated→annotated
Error Handling
- Network or decode failure returns error; upstream marks progress failure.
- Annotation failure aborts after raw image write (annotated artifact missing).
- Missing API key: annotated placeholder is empty file (still allows cache semantics).
Customization Points
- Change model: patch selection logic near
modelNamevariable. - Bypass annotation: replace
annotateFuncvar in tests or fork logic. - Add watermark: extend
Annotateto composite additional graphics.
Next: Progress Tracking