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

[Android] When selecting image from gallery or taking photo, image loses orientation #379

Closed
joeferraro opened this issue Jul 18, 2017 · 36 comments

Comments

@joeferraro
Copy link
Contributor

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.14.1
  • react-native v0.43.1

Platform

  • Android

Expected behaviour

  • Take photo or select photo from gallery
  • Image is saved locally with original orientation

Actual behaviour

  • Take photo or select photo from gallery
  • Image is saved locally without the original orientation

Steps to reproduce

ImagePicker.openPicker({
  cropping: false,
  includeBase64: true,
  compressImageQuality: 0.5,
});

Important This only occurs when cropping is set to false and compressImageQuality is set to a value less than 1.

@ivpusic
Copy link
Owner

ivpusic commented Jul 18, 2017

do you have some time to take a look into this?

@joeferraro
Copy link
Contributor Author

@ivpusic this issue seems related to Compressor. v2.1.0 of Compressor attempts to resolve the issue but there seems to be a regression for compressed images taken by the camera as I've noted here.

@ferminmoli
Copy link

Is there any news about this? Image is loosing it's orientation

@ferminmoli
Copy link

I updated to 0.16.0 version (The last one) and Taking photo from camera is crashing on Android. Please, I need help with this.

@WLYau
Copy link

WLYau commented Sep 18, 2017

Hi, I'm experiencing the same issue, have updated to the latest version and the image still gets rotated? Anymore news on this?

We're using react-native version 0.39.2

@dinatazy
Copy link

Happens also with me on IOS. Image is rotated upside down. Any updates on this issue?

@jonathanroze
Copy link

Any updates ?

@dinatazy
Copy link

dinatazy commented Nov 9, 2017

@Clowning It turns out it's not the library's issue. my solution was that I get the Exif data by setting property includeExif to true. the exif object includes an orientation number. Each number indicates a specific orientation so , based on the orientation number you can rotate the image to its original position again.

@isaachinman
Copy link

isaachinman commented Jul 10, 2018

@dinatazy I just hit this issue myself. Strange that more people haven't encountered it. When an image has this Orientation EXIF field set, react-native-image-crop-picker will actually swap the image dimensions, but leaves the rotation itself up to the end user. This confusing "half" approach created a bug in my app, and it took me some time to track it down to here.

I would expect react-native-image-crop-picker to leave the width and height values alone, and leave all manipulation to the discretion of the end user.

Thoughts?

@isaachinman
Copy link

If anyone else is affected by this, the fix in my case was to simply ignore the dimensions that react-native-image-crop-picker provides and just use RN natively:

Image.getSize(image.path, (width, height) =>

@Jyrno42
Copy link

Jyrno42 commented Aug 16, 2018

Having a similar issue. If anyone got a fork or an example how they got it working i would love to see it.

@drewandre
Copy link

drewandre commented Nov 28, 2018

Also seeing this issue, and it seems to be directly related to this issue for react-native-image-picker: react-native-image-picker/react-native-image-picker#655

More info about the exif orientation data that is returned ("0", "1", etc) can be found here: https://developer.android.com/reference/android/support/media/ExifInterface.html#TAG_ORIENTATION

I decided to modify the width and height based on the orientation data:

.then(photo => {
  if (Platform.OS === 'android') {
    let { width, height } = this.handlePhotoOrientation(photo)
    photo.width = height
    photo.height = width
  }
})
handlePhotoOrientation = photo => {
  let photoOrientationData = photo.exif.Orientation
  let width, height
  if (photoOrientationData) {
    switch (parseInt(photoOrientationData)) {
      case 1: // ORIENTATION_NORMAL (values should be swapped)
        return {
          width: height,
          height: width
         }
    case 3: // ORIENTATION_ROTATE_180 (values should be swapped)
      return {
        width: height,
        height: width
       }
     default:
        return {
          width: photo.width,
          height: photo.height
        }
    }
  } else {
    return {
      width: photo.width,
      height: photo.height
    }
  }
}

bonesyblue added a commit to lokalportal/react-native-image-crop-picker that referenced this issue Apr 17, 2019
…images (ivpusic#379)

When using the image compression options, the returned resized image orientation differed from the original image. This caused selected images to often be rotated.

Original issue thread:
ivpusic#379
@bonesyblue
Copy link
Contributor

I've created a PR with a fix for this issue, feel free to check it out and leave feedback 👍

bonesyblue added a commit to lokalportal/react-native-image-crop-picker that referenced this issue Apr 17, 2019
…images (ivpusic#379)

When using the image compression options, the returned resized image orientation differed from the original image. This caused selected images to often be rotated.

Original issue thread:
ivpusic#379
bonesyblue added a commit to lokalportal/react-native-image-crop-picker that referenced this issue Apr 17, 2019
…images (ivpusic#379)

When using the image compression options, the returned resized image orientation differed from the original image. This caused selected images to often be rotated.

Original issue thread:
ivpusic#379
ivpusic pushed a commit that referenced this issue Apr 26, 2019
…images (#379) (#986)

When using the image compression options, the returned resized image orientation differed from the original image. This caused selected images to often be rotated.

Original issue thread:
#379
@ivpusic
Copy link
Owner

ivpusic commented Apr 26, 2019

should be fixed in https://github.com/ivpusic/react-native-image-crop-picker/releases/tag/v0.24.0

@ivpusic ivpusic closed this as completed Apr 26, 2019
@ahartzog
Copy link

Super excited for this fix! What's the usual release timeline to NPM? Trying to decide if I should install from the 0.24.0 release directly or wait for npm.

@ivpusic
Copy link
Owner

ivpusic commented Apr 27, 2019

published now

@CrisHemswerthThor
Copy link

CrisHemswerthThor commented May 20, 2019

I have installed version 0.24.0 but facing the same image rotation issue .Please provide me some solution.

My code is given below:

`//function defined for handling the onPress event of Camera
_openCamera() {
ImagePicker.openCamera({

  compressImageMaxHeight:windowH*0.60,

  mediaType: 'photo',

}).then(image => {

  let photoPathFromCamera = image.path.replace('file://', '')

  //image coming from camera opens in RNPhotoEditor

  RNPhotoEditor.Edit({
    path: photoPathFromCamera,
    hiddenControls: ['crop']
  });

});

}`

Version:
react-native-image-crop-picker v0.24.0
react-native v0.59.3

Issue:
In my case ,the image does't rotate in debug mode but in case of release apk the image rotates automatically with the same code and I don't know why this is happening . It's really frustrating .

@twelve17
Copy link

twelve17 commented Jun 20, 2019

@ivpusic - thanks for working on the fix for this issue. I looked over the updated code:

int rotationAngleInDegrees = getRotationInDegreesForOrientationTag(originalOrientation);

I might be misreading it, but is my understanding correct that the code is doing the following:

  1. obtaining the rotation data from EXIF
  2. applying the rotation to the image when resizing

In other words, if the compression step "applying" the exif orientation to the resized image, should it remove the orientation info from its EXIF data now that it's been applied? Otherwise a future consumer of the image might think it needs to be rotated again?

@dphaener
Copy link

To add to @twelve17 comment above, version 0.24.0 is not fixing this for us. We are still seeing this issue with RN v0.57.8.

@karltaylor
Copy link

Also getting this issue on version 0.25.0

# react-native info
System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    Memory: 61.71 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.4.0 - /usr/local/bin/node
    Yarn: 1.17.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.4

@cayasso
Copy link

cayasso commented Oct 22, 2019

Can this issue be reopen, I am having this same issue in the latest version (0.26.1).

adylevy pushed a commit to Homeisapp/react-native-image-crop-picker that referenced this issue Nov 19, 2019
* Add chooseText and cancelText properties: rebased (ivpusic#699)

* Add cancel and choose buttons text properties

* Change props names to ‘cancelText’,’chooseText’

* Add cancel and choose buttons text props

* Fix properties names IOS

* Add cropper prefix and update readme

* Add cloud support (Android) (ivpusic#650)

* Add cloud support - workd in progress

* Fix extension issue

* Remove log, unused import

* Fix regression (MIME_TYPE for action_get_document)

* (android) Upgrade ucrop to 2.2.2. Upgrade react-native for example project. Cleanup picker module

* version bump

* (android) Result collector improvements

* version bump

* Update README.md

* Update README.md

* Update README.md

* Reduce size of default compressed files, update README (ivpusic#736)

* [fix/android] Android API version under 19 crash fix (ivpusic#741)

* Convert unknown file types to JPEG (ivpusic#735)

* Added android equivalent code to iOS code. (ivpusic#749)

* Revert "Added android equivalent code to iOS code. (ivpusic#749)" (ivpusic#750)

This reverts commit 97ce8ba.

* Added android equivalent code for skipping image compression. (ivpusic#753)

* Added android equivalent code to iOS code.

* Fix invalid variable.

* Added option to configure avoidEmptySpaceAroundImage (ivpusic#765)

* Added option to configure avoidEmptySpaceAround image

* Added missing interface option

* Fixes uncasted bool value

* Add new logo/icon (ivpusic#768)

* Upload new logo

* Add new logo to README

* Add new to mipmap hdpi

* Add new to mipmap mdpi

* Add new to mipmap mdpi

* Add new to mipmap mdpi

* add new to mipmap mdpi

* Add new to mipmap mdpi

* Add new to mipmap mdpi

* Add new to mipmap mdpi

* Add new to mipmap xhdpi

* Add new to mipmap xhdpi

* Add new to mipmap xhdpi

* Add new to mipmap xhdpi

* Add new to mipmap xxhdpi

* Add new to mipmap xxhdpi

* Add new to mipmap xxhdpi

* Add new to mipmap xxhdpi

* Add new to mipmap xxhdpi

* Add new to mipmap xxhdpi

* Add new to mipmap xxhdpi

* Upload new logo svg

* Update README with new logo

* delete

* Upload New logo svg

* Update README

* Update README.md

* Use project-wide properties and new dependency (ivpusic#771)

* Support for gradle 3.+

* Add cropperToolbarTitle into TypeScript typings (ivpusic#777)

* Fix a bug when the file name contains slashes. (ivpusic#775)

It can happen when selecting an image downloaded from Weibo app.

* Change screen orientation so android will detect and change to match screen fixes issue ivpusic#733 (ivpusic#766)

* Adds forceJpg flag to convert live photos (ivpusic#791)

* Adds property to filter live photos

* Force JPG image conversion

* Renames forceJPG -> forceJpg

* [DEVOPS] version bump

* Revert to compile (ivpusic#796)

* [DEVOPS] Version bump

* add license scan

* Set options.networkAccessAllowed = YES in getVideoAsset to prevent freezing when attempting to get videos stored in the cloud (ivpusic#772)

* Fix typo on example (ivpusic#809)

* Fall back to writing to file if _data column does not exist (ivpusic#817)

* Fall back to writting to file if _data column does not exist

* Fix spelling

* Update README.md

* Update README.md (ivpusic#826)

Add optional configuration details about default ios text button for the camera and the gallery

* Diegolmello master (ivpusic#834)

* [FIX] Poor image quality after cropping

* Update README.md (ivpusic#826)

Add optional configuration details about default ios text button for the camera and the gallery

* [IMPROVEMENT] fix android cropping height condition. update podfile lock

* version bump

* Update README.md (ivpusic#851)

* Update PickerModule.java (ivpusic#862)

Fix for default values being kept when calling cropPicker from multiple locations.

Now default values if not passed will be reverted to default.

* version bump

* Add front camera support for android (ivpusic#876)

* Add front camera support for android

* Update readme

* Update readme

* Update README.md

* Added missing flags to support front camera on some android phones (ivpusic#891)

* Remove problematic step from manual post-install steps (ivpusic#821)

* (ios) fix images are not resized after cropping. Fixes ivpusic#843

* (ios) add example project xcshareddata

* (feature) video recording (ivpusic#917)

* Android: Add video recording support

- Caveats:
  - Wont work if cropping is enabled
- Video recording will be used if mediaType is set to 'video'
  - Mediatype any is not supported since there is no standard intent for capture image or video

* IOS: Add video recording support

- Caveats:
  - Cropping does not work

Video recording will be enabled if mediaType is set to `video` or `any`. Note: With any the native ui
allows the user to choose whether to take a photo or record a video. This differs from android where
mediaType any will just allow taking photos.

* IOS: Set camera video quality to high

* Update README.md (ivpusic#851)

* Update PickerModule.java (ivpusic#862)

Fix for default values being kept when calling cropPicker from multiple locations.

Now default values if not passed will be reverted to default.

* version bump

* Add front camera support for android (ivpusic#876)

* Add front camera support for android

* Update readme

* Update readme

* Update README.md

* Added missing flags to support front camera on some android phones (ivpusic#891)

* Remove problematic step from manual post-install steps (ivpusic#821)

* (ios) fix images are not resized after cropping. Fixes ivpusic#843

* (ios) add example project xcshareddata

* (ios) fixes for camera recording. updated example project with camera recording. updated readme with camera recording

* unify ios and android camera response. Fixes ivpusic#872

* version bump

* Update README.md

* Simplify `includeBase64` (ivpusic#918)

If `image.data` is already base64 encoded string, why do we need this wrapper?
The proposed change worked for me on ios and android.

* Make example config valid json (ivpusic#927)

* (android) cropping and resizing improvements

* (android) simplify options parsing

* android libs and package.json version bump

* Remove images from npm bundle (ivpusic#960)

* upgrade example project to react-native 0.59

* fix ios camera with cropping not reject on cancel cropping (ivpusic#954)

* fix ios camera with cropping not reject on cancel cropping

* cancel properly from opencropper

* replace compile with implementation in build.gradle

* version bump

* Add some types for Image interface (ivpusic#973)

* (android) add showCropFrame option (ivpusic#972)

* Fix Android image rotation issue when compressing gallery and camera images (ivpusic#379) (ivpusic#986)

When using the image compression options, the returned resized image orientation differed from the original image. This caused selected images to often be rotated.

Original issue thread:
ivpusic#379

* version bump

* example project support for android 9

* fixed bug with iOS cancel button (ivpusic#1000)

* version bump

* autoclose inputstream when base64 image file (ivpusic#1040)

* Fix when Pictures directory is not existing on device (ivpusic#1027)

* Update pod dependency to support rn 0.60 (ivpusic#1019)

* Update pod dependency to support rn 0.60

* Update RNImageCropPicker.podspec

* update android support library to androidx (ivpusic#1048)

* Update PickerModule.java

* Update RealPathUtil.java

* Update AndroidManifest.xml

* finishing support for react-native 0.60

* add installation notes for react-native 0.60

* Clarify README.md (ivpusic#1065)

React Native 0.60 higher requires you to manually install the pods after auto linking

* Clarify README.md (ivpusic#1058) (ivpusic#1074)

Not all Android devices handle useFrontCamera

* Adds a sortOrder flag to sort by creation date on iOS (ivpusic#1090)

* Adds a sortOrder flag to sort by creation date on iOS

* Removes extraneous sortOrder access

* check permission before startCropping. Fix of ivpusic#957 (ivpusic#1095)

* version bump

* Revert "Adds a sortOrder flag to sort by creation date on iOS (ivpusic#1090)"

This reverts commit 33fd526.

* version bump

* fixed `jitpack.io` url in readme.md (ivpusic#1115)

* Added iOS 13 DarkMode for picker (ivpusic#1129)

* Update README.md

* version bump

* HOM-3770 fix merge issues

* HOM-3770 restore video compression utility
@BogdanRad
Copy link

BogdanRad commented May 20, 2020

I have some problem on 0.31.1 .... are you a solution for this?

@thiago-sandes
Copy link

Some problem on 0.32.2. #IOS

@nitin-gwl
Copy link

Same problems with 0.32.2. #Android Version 9 (Samsung Galaxy S8).

@namansukhwani
Copy link

I am facing the same issue in open camera images only on android image from open camera is rotated by 90 degrees by itself.
do any one have
a solution ???

@eubnara
Copy link

eubnara commented Oct 21, 2020

How about trying option compressImageQuality: 0.99?
It removes exif metadata by compressing but rotates correctly.

I experience wrong rotation problem but I finally know that the problem comes from others.

I use react-native-image-resizer. Even though I set keepMeta: true, it loses orientation.
(it is explained in https://github.com/bamlab/react-native-image-resizer#promise-createresizedimagepath-maxwidth-maxheight-compressformat-quality-rotation--0-outputpath)

Anyway, maybe your image may go through some kind of compression or else and loses exif metadata and it makes your image seen in a wrong way.
So I just use compressImageQuality: 0.99 and make exif metadata removed in advance.

@ngocht143
Copy link

ngocht143 commented Dec 16, 2020

@eubnara Yours worked for me 👍 don't know the reason

@15110011
Copy link

Taking a photo and then it is still rotated on the newest version
0.35.2

@nmhoan76
Copy link

Still for version 0.36.. @ivpusic Please check it

@mojtabaasadi
Copy link

Applied @eubnara solution, problem still persists on 0.37.2

@developer-appdam
Copy link

I tried @eubnara solution but my images are still rotated. I have no clue why but they just keep rotating. Any tip?

@subhadeepquantiantech
Copy link

any update?

@gkasireddy202
Copy link

gkasireddy202 commented Aug 18, 2023

Same problem on v0.40.0.
#1960

@gkasireddy202
Copy link

@karltaylor - This below code works in v0.40.0?

Also seeing this issue, and it seems to be directly related to this issue for react-native-image-picker: react-native-image-picker/react-native-image-picker#655

More info about the exif orientation data that is returned ("0", "1", etc) can be found here: https://developer.android.com/reference/android/support/media/ExifInterface.html#TAG_ORIENTATION

I decided to modify the width and height based on the orientation data:

.then(photo => {
  if (Platform.OS === 'android') {
    let { width, height } = this.handlePhotoOrientation(photo)
    photo.width = height
    photo.height = width
  }
})
handlePhotoOrientation = photo => {
  let photoOrientationData = photo.exif.Orientation
  let width, height
  if (photoOrientationData) {
    switch (parseInt(photoOrientationData)) {
      case 1: // ORIENTATION_NORMAL (values should be swapped)
        return {
          width: height,
          height: width
         }
    case 3: // ORIENTATION_ROTATE_180 (values should be swapped)
      return {
        width: height,
        height: width
       }
     default:
        return {
          width: photo.width,
          height: photo.height
        }
    }
  } else {
    return {
      width: photo.width,
      height: photo.height
    }
  }
}

@gkasireddy202
Copy link

@dphaener - Not getting photo.exif.Orientation when I captured images from the camera.

Getting below JSON object:

{"height": 3000, "mime": "image/jpeg", "modificationDate": "1694499770000", "path": "file:///storage/emulated/0/Android/data/com.myapp/files/Pictures/image-a92fa6d9-5308-4316-a9c5-026ee0c83f8c8876211762320268300.jpg", "size": 5275914, "width": 4000}

@gkasireddy202
Copy link

I rotated the image rotation 0 using npm:react-native-image-resizer before uploading it to the server.
works fine.

secretdev718 added a commit to secretdev718/React-Native-ImagePicker that referenced this issue Sep 4, 2024
…images (#379) (#986)

When using the image compression options, the returned resized image orientation differed from the original image. This caused selected images to often be rotated.

Original issue thread:
ivpusic/react-native-image-crop-picker#379
dev-arrow added a commit to dev-arrow/react-native-image-crop-picker that referenced this issue Nov 25, 2024
…images (#379) (#986)

When using the image compression options, the returned resized image orientation differed from the original image. This caused selected images to often be rotated.

Original issue thread:
ivpusic/react-native-image-crop-picker#379
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

No branches or pull requests