Fix image dimensions info when the file has some EXIF orientation (Android) #343
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.
Summary
In our App, we want to display only the landscape (horizontal) pictures from the user's gallery. To do so, we check the
width
andheight
data given by the lib when callingCameraRoll.getPhotos(...)
. Unfortunately the data is incorrect on some devices (e.g. Xiaomi Redmi Note 5) where width and height are swapped around.Root problem
Pictures taken with the native camera app may set the EXIF orientation property instead of rotating the pixel data. When reading the Bitmap data, you need to check the EXIF attributes and apply the required rotation (if any). Currently the lib assumes that there isn't any rotation to be done.
Solution
I added code in
putImageSize(...)
to check the EXIF data and swap the width / height data if necessary. It will apply the check whether the size data is retrieved from the cursor's columns or by reading the Bitmap data. The performance impact should be very small as we are only loading the file headers and reusing the file handle.Test Plan
There is no API change. Testing entails calling
CameraRoll.getPhotos({ include: ['imageSize'], assetType: 'Photos' })
on a device with pictures that have EXIF rotation data.What's required for testing (prerequisites)?
You need either:
What are the steps to reproduce (after prerequisites)?
console.log(asset)
at line 180 in_appendAssets(data)
node.image.width
andnode.image.height
are correctCompatibility
Checklist
README.md
(no change needed)example/App.js
) (no change needed)