Repository navigation
Studio: apply EXIF orientation to uploaded images - #10553
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Review + GitHub Actions reproductionPinned head: The defect and the fix are reproduced by an A/B job on fresh upstream The probe feeds
The mask row is the inpaint case: the mask arrives at the preview's size and the source did not, so the brushed region landed on a different part of the picture.
The size guard reads the header dimensions before the transpose, so it is unchanged by this: the parametrised case asserts all eight orientation values decide |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Studio UI evidence: before / afterTwo isolated Studio installs on one A10G, base The upload is a four-colour card whose pixels are stored 768x448 landscape with EXIF Every fact that moved, and nothing else:
BEFORE, the run generated at the size of the stored pixels and in the stored quadrant order — the orientation nobody saw. AFTER it matches the preview. The quadrant read is deliberately mirror-sensitive. Orientation 5 is the diagonal flip of orientation 6 and produces the same sizes, so a size-only check cannot tell a rotation from a mirror; the colours can. |
Orientation was applied with ImageOps.exif_transpose, which resolves the tag through Image.getexif(). That also recovers orientation from XMP tiff:Orientation and from ImageMagick's hex text profile, neither of which Chromium applies, and it may have cached one of those while open() read the DPI, so stripping the metadata afterwards is too late. A file the preview left upright then decoded rotated, which lands an inpaint mask transposed against its own source and repaints a region the user never brushed. The orientation is now read directly out of the EXIF block and applied from an explicit table, so no fallback source and no cache can reach it. A malformed block no longer propagates out of the tag parse, which had turned a previously accepted upload into a 400. WebP is skipped because Chromium does not orient it while WebKit does, leaving a known macOS divergence that no single server-side rule can close. Every orientation source is dropped after a transpose so a re-save cannot apply it twice. Tests drive real files through the decoder: all eight tag values against a table read off the tag definitions rather than off Pillow, both metadata fallbacks, the orientation cached during open(), a malformed block, a PNG eXIf chunk, WebP, and the size guard's ordering against the transpose.
|
Pushed a commit to this branch ( What changed and why:
Every orientation source is also dropped after a transpose, so a re-save can't apply it twice. Your test file is kept and extended — the eight-orientation table and the mirror-vs-rotation fixture were what caught most of this, and a rotate-only fix still fails orientations 2, 4, 5 and 7. Added cases for both metadata fallbacks, the cached-orientation path, the malformed block, a PNG Two things deliberately left alone, both worth separate PRs:
Also worth noting the title now over-promises slightly: the chat and VLM upload paths ( |
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Lyxot
left a comment
There was a problem hiding this comment.
Approving. The bug is real: the mask canvas is sized from naturalWidth/naturalHeight, which the browser has already orientation-corrected, so a phone photo with a rotation tag reached the backend as an unrotated buffer and the mask no longer lined up with it.
The fix reads the EXIF block directly rather than through getexif(), which is the right call — getexif() also recovers orientation from XMP and ImageMagick text profiles that no browser honours, and can hand back a value it cached during open(). Reading info["exif"] alone keeps the backend agreeing with what the user saw. The WebP skip and the metadata cleanup after the transpose are both correct and both covered.
Tests pin all eight orientation values against expected size and corner colours, plus the XMP-only, EXIF-vs-XMP conflict, text-profile, malformed-block and double-apply cases. Verified locally, including that the transpose runs after the size guard.
Two things left for follow-up, neither blocking here: the chat/VLM upload paths do not go through decode_b64_image and still ignore orientation, and the inpaint mask is still resized unconditionally when it does not match the source.

A photo taken on a phone carries a rotation tag. The browser preview honours it, but the backend decoded the raw pixels, so Transform, Edit, Inpaint and video keyframes worked on a sideways image while the user saw it upright.
Inpaint was the worst case. The mask is drawn at the preview size, so it arrived transposed against the source and the model repainted a different part of the picture than the one the user brushed.
The decoder now applies the orientation tag in place, the same way the training loaders already do. Images without a tag are untouched.
The tests drive real rotated JPEGs through the decoder and check all eight orientation values against a table read off the tag definitions, asserting the decoded size and which stored quadrant lands in each display corner. Four of the eight are mirrors, so a fix that rotated where it should flip does not pass on sizes alone. They also pin the two properties around the change: the tag never decides whether an image is accepted, and an oversized image is still refused from the header before its pixels are read.