Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix Android image dimensions for rotated EXIF orientations

Anand Baburajan07038ea0c0c9
diff --git a/mobile/apps/photos/lib/utils/file_uploader_util.dart b/mobile/apps/photos/lib/utils/file_uploader_util.dart
index fda7ae2b8f..0d5ad39dd3 100644
--- a/mobile/apps/photos/lib/utils/file_uploader_util.dart
+++ b/mobile/apps/photos/lib/utils/file_uploader_util.dart
@@ -193,8 +193,15 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
isDeleted = !(await asset.exists);
int? h, w;
if (asset.width != 0 && asset.height != 0) {
- h = asset.height;
w = asset.width;
+ h = asset.height;
+ if (Platform.isAndroid &&
+ file.fileType == FileType.image &&
+ _shouldSwapDimensionsForExifOrientation(exifData)) {
+ final temp = w;
+ w = h;
+ h = temp;
+ }
}
int? motionPhotoStartingIndex;
if (Platform.isAndroid && asset.type == AssetType.image) {
@@ -219,6 +226,12 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(
);
}
+bool _shouldSwapDimensionsForExifOrientation(Map<String, IfdTag>? exifData) {
+ final orientation = exifData?['Image Orientation']?.values.firstAsInt() ?? 1;
+ // EXIF orientations 5-8 are rotated 90/270 variants and require w/h swap.
+ return orientation >= 5 && orientation <= 8;
+}
+
Future<int?> motionVideoIndex(Map<String, dynamic> args) async {
final String path = args['path'];
final videoIndex = await getMotionVideoIndex(filePath: path);