21
21
22
22
import androidx .core .app .ActivityCompat ;
23
23
import androidx .core .content .FileProvider ;
24
+ import androidx .exifinterface .media .ExifInterface ;
24
25
25
26
import com .facebook .react .bridge .ActivityEventListener ;
26
27
import com .facebook .react .bridge .Callback ;
@@ -678,6 +679,15 @@ private WritableMap getImage(final Activity activity, String path) throws Except
678
679
throw new Exception ("Cannot select remote files" );
679
680
}
680
681
BitmapFactory .Options original = validateImage (path );
682
+ ExifInterface originalExif = new ExifInterface (path );
683
+ int orientation = originalExif .getAttributeInt (ExifInterface .TAG_ORIENTATION , 1 );
684
+ boolean invertDimensions = (
685
+ orientation == ExifInterface .ORIENTATION_ROTATE_90 ||
686
+ orientation == ExifInterface .ORIENTATION_ROTATE_270 ||
687
+ orientation == ExifInterface .ORIENTATION_TRANSPOSE ||
688
+ orientation == ExifInterface .ORIENTATION_TRANSVERSE
689
+ );
690
+
681
691
682
692
// if compression options are provided image will be compressed. If none options is provided,
683
693
// then original image will be returned
@@ -687,8 +697,8 @@ private WritableMap getImage(final Activity activity, String path) throws Except
687
697
long modificationDate = new File (path ).lastModified ();
688
698
689
699
image .putString ("path" , "file://" + compressedImagePath );
690
- image .putInt ("width" , options .outWidth );
691
- image .putInt ("height" , options .outHeight );
700
+ image .putInt ("width" , invertDimensions ? options . outHeight : options .outWidth );
701
+ image .putInt ("height" , invertDimensions ? options . outWidth : options .outHeight );
692
702
image .putString ("mime" , options .outMimeType );
693
703
image .putInt ("size" , (int ) new File (compressedImagePath ).length ());
694
704
image .putString ("modificationDate" , String .valueOf (modificationDate ));
0 commit comments