react-native-image-resizer icon indicating copy to clipboard operation
react-native-image-resizer copied to clipboard

orientation / rotation bug

Open zkrige opened this issue 7 years ago • 15 comments

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?

zkrige avatar Jun 28 '17 13:06 zkrige

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).

4ian avatar Jun 28 '17 14:06 4ian

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?

zkrige avatar Jun 29 '17 09:06 zkrige

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. :/

4ian avatar Jun 29 '17 10:06 4ian

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

UKulikov avatar Jul 07 '17 15:07 UKulikov

Any solutions?

I think the same, returning this one line of code, will be the right way -

Bitmap rotatedImage = ImageResizer.rotateImage(scaledImage, rotation);

UKulikov avatar Jul 11 '17 17:07 UKulikov

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 avatar Sep 02 '17 09:09 antoinerousseau

@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 avatar Mar 31 '18 15:03 embpdaniel

@embpdaniel I ended up coding my own fork, check my commit: https://github.com/antoinerousseau/react-native-image-resizer/commit/e027be074669d5990daf3976957f911abc583e9a

antoinerousseau avatar Mar 31 '18 17:03 antoinerousseau

Thanks @antoinerousseau your fork worked for me.

embpdaniel avatar Apr 02 '18 14:04 embpdaniel

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 😢

4ian avatar Apr 02 '18 14:04 4ian

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 ;)

antoinerousseau avatar Apr 03 '18 07:04 antoinerousseau

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

kleyos avatar Aug 08 '18 07:08 kleyos

Same here, taking images in portrait mode sets rotation to -90deg

Volekss avatar Nov 02 '20 18:11 Volekss

Still finding this is an issue, is there a fix incoming?

chris44f avatar Dec 10 '20 11:12 chris44f

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.

atorgfr avatar Dec 22 '20 15:12 atorgfr

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.

stale[bot] avatar Sep 01 '22 18:09 stale[bot]

This issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Sep 08 '22 18:09 stale[bot]