react-native-image-resizer
react-native-image-resizer copied to clipboard
orientation / rotation bug
When I take a photo with Samsung S8 in portrait mode, the camera app tells me orientation is 90.
If I apply this orientation to the resize, the image comes out correct. However, this now breaks every single other device.
Surely the rotate could should look like like this
Bitmap rotatedImage = ImageResizer.rotateImage(scaledImage, rotation);
instead of
Bitmap rotatedImage = scaledImage;
int orientation = getOrientation(context, Uri.parse(imagePath));
rotation = orientation + rotation;
rotatedImage = ImageResizer.rotateImage(scaledImage, rotation);
I cant understand why we would want to rotate by exif orientation PLUS whatever rotation value the user passes in?
rotation
value passed by the user is a simple convenience parameter to allow rotating images resized for whatever usage 😃
The exif orientation is used to ensure that the image comes out correct. But looks like exif is not properly reported on Samsung devices.
I remember having the same issue with different Samsung devices (S5, S6) whereas the resulting orientation was correct on other devices. I worked around by passing an extra rotation value based on the orientation returned by react native camera (if i remember properly).
If I pass an extra rotation value based on the orientation returned by react native camera, then it breaks for a bunch of other android devices.
Were you explicitly ONLY doing this for Samsung devices?
I wasn't doing this explicitly only for samsung devices, but I can't remember what was the trick. I think it was based on react native camera or images information. :/
I have quiet similar bug. Device is Samsung Galaxy Alpha.
If i pick photo from the gallery, all is ok. Rotation is the same as in gallery in all conditions. But if i take photo,it's starts to rotating. If rotation 0 - it's ok. But in all other conditions it's rotating. 90 - rotating to the right 90 degrees (make it horizontal, but picture was taken vertical), 180 rotating to 180, 270 to 270 degrees. All vertical photos output is horizontal, horizontal photos 180 rotation - it's upside down. All is ok only if rotation 0.
I think this one is relation to this. #36
Any solutions?
I think the same, returning this one line of code, will be the right way -
Bitmap rotatedImage = ImageResizer.rotateImage(scaledImage, rotation);
With my LG G3, taking a photo gives this URI:
content://plus.wedo.village.provider/app_images/Pictures/image-475faae8-e255-4e1e-8ae6-dc8bae35d730.jpg
but in getOrientation
, file.exists()
returns false
, which makes the function return 0
... I guess getFileFromUri
is broken?
@antoinerousseau I have the same exact issue. I have an LG stylo, and when I take a photo I get a similar URI as yours:
content://com.myapp.dev.provider/app_images/Android/data/com.myapp.dev/files/Pictures/image-853eca23-198c-471d-bd2d-127780ed0206.jpg
getOrientation
fails because getFileFromUri
cannot find the file .
If I pick an image from the library on the same device I get a different URI, for example: file:///data/user/0/com.myapp.dev/cache/1522442787293.JPEG
getOrientation
works fine in this case.
@embpdaniel I ended up coding my own fork, check my commit: https://github.com/antoinerousseau/react-native-image-resizer/commit/e027be074669d5990daf3976957f911abc583e9a
Thanks @antoinerousseau your fork worked for me.
If you think that you have a good solution I'm happy to merge any PR that could improve things 😄
Unfortunately I don't have much time to update the module these times, I'm not actively using it anymore 😢
I didn't make a PR of my fork because it's a simplification, so I don't want to remove features from your repo ;)
Android. When I set the parameter of rotation image resizer does nothing. My photo is added with original rotation. The previous recipes don't help
Same here, taking images in portrait mode sets rotation to -90deg
Still finding this is an issue, is there a fix incoming?
After looking for this issue, the problem on android is about file from content://... The getFileFromUri doesn't return an existing file for file starting with content:// don't know why. So in getOrientation method you can't ask for Exif data and the rotation cannot be found. I've tried to found a way to get the real path from content:// but without success.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed. Thank you for your contributions.