Repository navigation
Add --aspect-ratio for backend-verified image framing - #21
Open
LingMoe404 wants to merge 3 commits into
Open
LingMoe404 wants to merge 3 commits into
LingMoe404 wants to merge 3 commits into
Conversation
The tested backend ignores the request's size field when framing an image: a request for 1024x1536 comes back square, and both the native and Responses paths behave the same way. Prompt wording is what actually controls the frame, so expose that as a first-class option rather than leaving users to discover it. --aspect-ratio W:H appends explicit framing guidance to the prompt and then verifies the returned image against the requested ratio through the existing --size-policy. Requests outside 1:3..3:1 are rejected locally because the backend clamps them and would otherwise surface as a confusing mismatch. The size field is left untouched: the ratio is prompt guidance, not a disguised size. The returned image is never resized or cropped to hide a mismatch, matching the project's existing boundary. Covered by 43 offline tests. Live checks returned the requested ratio on every attempt (2:3 -> 1024x1536, 16:9 -> 1672x941, 21:9 -> 1916x821, 1:1 -> 1254x1254, 9:18 -> 887x1774, 3:1 -> 2172x724), including edit mode.
The previous wording said a request beyond 3:1 "will be reported as a mismatch", but --aspect-ratio rejects anything outside 1:3..3:1 during argument parsing, so a 4:1 request never reaches the backend. Describe what the CLI actually does, and keep the live observation that motivated the local check.
Framing now precedes the scene description:
The frame must be in 2:3 portrait format, taller than it is wide.
A lighthouse at dusk
The published GPT-Image2 style-library templates put the ratio constraint
before the scene ("must be written first, otherwise the model defaults to
a phone 9:16"), and the ratio appears near the start of the prompt in most
of that library's 544 cases. A/B checks showed no behavioural difference
between the two orders on the tested backend, including the conflict case
of a portrait phone-screenshot prompt asked to render at 21:9, so order
follows the documented convention rather than a measured advantage.
Live re-checks after the change still returned the requested ratio on
every attempt (2:3 -> 1024x1536, 21:9 -> 1916x821, 16:9 -> 1672x941,
1:1 -> 1254x1254, and 2:3 on an edit).
foksa
added a commit
to foksa/codex-img
that referenced
this pull request
Oct 1, 2026
Live tests on the direct route showed the request's size field has no effect: 1024x1536 and 1536x1024 both came back at 1312x1199. A sentence stating the ratio at the start of the prompt gave that ratio every time, on generations and edits (a 2:3 input edited with 16:9 came back 16:9). -a/--aspect W:H (1:3 to 3:1) leads the prompt with that sentence and warns when the image comes back more than 2% off. It can't be combined with --size. batch takes an aspect field; the Python fallback takes the flag too. The docs now say -s is ignored, that edits reframe with -a, that ratio prompts come back reported as quality low with fewer image tokens, and that the model field isn't checked. Idea and pixel counts from jdmnk/codex-imagegen-cli#21. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sc9Qaa9KWor3Didh9k9sxN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Adds
--aspect-ratio W:Htogenerate,edit, andbatch.The tested backend ignores the request's
sizefield when framing an image. A request for--size 1024x1536comes back square (1254x1254on my account);--size 1024x1024and1536x1024also both came back square, and--backend responsesbehaves the same way. What does control the frame is the prompt.--aspect-ratioexposes that directly instead of leaving users to discover it by trial and error.codex-imagegen generate --prompt "A lighthouse at dusk" --out out.png --aspect-ratio 2:3The option prepends explicit framing guidance to the prompt and then verifies the returned image against the requested ratio through the existing
--size-policy:Design notes
sizefield is left untouched (auto), and--aspect-ratiois mutually exclusive with--size, so the two cannot silently disagree.1916x821), so the order follows the documented convention rather than a claimed advantage.--size-policy warn(default) saves the original dimensions and warns;--size-policy errorrefuses to write.4:1request came back at2172x724, i.e. 3:1) and would otherwise surface as a confusing mismatch after spending usage.2:3and getting9:16).Verification
Live checks on the tested backend returned the requested ratio on every attempt, including
edit:1:11254x12543:41086x14482:31024x15369:16941x16721:2887x177416:91672x94121:91916x8213:12172x724Every row was produced with the
--aspect-ratioflag itself. Re-checked after the ordering change with the same results. Returned frames follow the ratio at a roughly constant pixel budget (~1,572,864), which is why2:3and3:2land on exactly1024x1536and1536x1024. The README documents this and notes that exact pixel sizes still require a local crop or pad, since the backend chooses the final dimensions.Note
--aspect-ratiois a framing control, not an exact-pixel control: it gets the orientation and ratio right, and the table above is what the backend returned on one account rather than a guaranteed mapping.Tests
44 offline tests in
tests/test_aspect_ratio.pycovering parsing and limits, mutual exclusion with--size, prompt guidance and instruction ordering, mismatch detection,--size-policywarn/error behaviour (including preserving an existing output), that thesizefield staysauto, and that batch applies the flag to every job.All pre-PR checks from CONTRIBUTING pass, on Python 3.10 / 3.12 / 3.14:
CODEX_IMAGEGEN_LIVE_TEST=1 uv run pytest -m live -valso passes (2 passed). I did not add an aspect-ratio case to the live suite, since CONTRIBUTING describes that suite as three image requests and the new logic is covered offline; live ratio behaviour is reported above instead.Notes for review
--aspect-ratiois CLI-level forbatch, matching how--sizeand--qualityalready work there; it is not a per-job JSONL field.sizefield's semantics.--sizebehaviour is unchanged; the mismatch branch is reused rather than duplicated.