Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image dimensions info when the file has some EXIF orientation (Android) #343

Conversation

drash-course
Copy link
Contributor

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 and height data given by the lib when calling CameraRoll.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:

  • A device like the Xiaomi Redmi Note 5 that sets EXIF orientation data when taking pictures
  • A set of pictures with different EXIF orientation data

What are the steps to reproduce (after prerequisites)?

  • Open the example/ project
  • Go to example/js/CameraRollView.js
  • add console.log(asset) at line 180 in _appendAssets(data)
  • Connect an android device or simulator
  • Install and launch the app
  • Go to the "CameraRollExample"
  • check the logs and make sure the node.image.width and node.image.height are correct

Compatibility

OS Implemented
iOS not affected
Android

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md (no change needed)
  • I updated the typed files (TS and Flow) (no change needed)
  • I added a sample use of the API in the example project (example/App.js) (no change needed)

@hamzaouhssain1993
Copy link

hamzaouhssain1993 commented Sep 17, 2021

great solution man, hopefully it will get accepted soon

@theasc
Copy link

theasc commented Sep 17, 2021

Exactly what I needed, you saved my day bro !!

@Levalis
Copy link

Levalis commented Sep 17, 2021

We face the same problem and would like to see this merged as soon as possible

Copy link

@doranteseduardo doranteseduardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look OK, tested in a Xiaomi Redmi Note 9 Pro device.

@doranteseduardo doranteseduardo merged commit 60e0e8e into react-native-cameraroll:master Oct 10, 2021
bartolkaruza pushed a commit that referenced this pull request Oct 10, 2021
## [4.1.1](v4.1.0...v4.1.1) (2021-10-10)

### Bug Fixes

* **orientation:** fix width/height info using EXIF data ([#343](#343)) ([60e0e8e](60e0e8e))
@bartolkaruza
Copy link
Collaborator

🎉 This PR is included in version 4.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants