Skip to content

fix(android): read Exif orientation from the image data, not the file path - #226

Draft
retyui wants to merge 2 commits into
masterfrom
fix/android-exif-orientation-from-stream
Draft

retyui wants to merge 2 commits into
masterfrom
fix/android-exif-orientation-from-stream

Conversation

@retyui

@retyui retyui commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

H1: wrong crop. EXIF orientation is now read from the image data (ExifInterface(InputStream)) instead of a file:// path.

getOrientation first resolved the source to a File. That only works for file: URIs and for content: URIs that expose MediaStore.DATA, which scoped storage usually hides. For https: and data: sources it returned 0, so the crop rect was never remapped, while BitmapRegionDecoder crops raw, unrotated pixels. A portrait Orientation=Rotate90 photo served over HTTPS cropped the wrong region, transposed. iOS and web handle this correctly.

The existing display→raw rect remapping is kept, because it was already correct. It just never got a non-zero orientation for remote sources.

Cost: for remote URIs the source is opened a second time per crop (EXIF needs a stream, region decode needs random access). This is cheap on a Fresco disk-cache hit. Without Fresco it means a second download.

Known limitation, not changed here: EXIF mirror values 5–8 fall into else -> 0, so a mirrored source stays mirrored.

Verification

Not compiled. No :android:compileDebugKotlin run and nothing run on a device. The Kotlin was checked for syntax errors only, and the external API signatures were checked against the published artifacts.

Split out of #221 (now closed), which bundled six Android fixes in ImageEditorModuleImpl.kt. Each one can be reviewed and merged separately.

… path

`getOrientation` resolved the source to a `File` first, which only works for
`file:` URIs and for `content:` URIs that expose `MediaStore.DATA` (usually
not the case under scoped storage). For `https:` and `data:` sources it
returned 0, so the crop coordinates were never remapped — while
`BitmapRegionDecoder` crops raw, un-rotated pixels. A portrait photo taken
with `Orientation=Rotate90` and served over HTTPS cropped the wrong part of
the image entirely, and the crop was transposed. iOS and web both handle
this correctly, so Android was the odd one out for every remote rotated
image.

Read the tag from a stream over the source instead, which works for every
URI scheme the module accepts. Sources without Exif data stay upright
rather than failing the crop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant