Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
4 changes: 4 additions & 0 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.1+10

* iOS: Fix image orientation problems when scaling images.

## 0.6.1+9

* Remove AndroidX warning.
Expand Down
14 changes: 14 additions & 0 deletions packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ + (UIImage *)scaledImage:(UIImage *)image
scale:1
orientation:UIImageOrientationUp];

// The image orientation is manually set to UIImageOrientationUp which swapped the aspect ratio in
// some scenarios. For example, when the original image has orientation left, the horizontal
// pixels should be scaled to `width` and the vertical pixels should be scaled to `height`. After
// setting the orientation to up, we end up scaling the horizontal pixels to `height` and vertical
// to `width`. Below swap will solve this issue.
if ([image imageOrientation] == UIImageOrientationLeft ||
[image imageOrientation] == UIImageOrientationRight ||
[image imageOrientation] == UIImageOrientationLeftMirrored ||
[image imageOrientation] == UIImageOrientationRightMirrored) {
double temp = width;
width = height;
height = temp;
}

UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 1.0);
[imageToScale drawInRect:CGRectMake(0, 0, width, height)];

Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors:
- Flutter Team <[email protected]>
- Rhodes Davis Jr. <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker
version: 0.6.1+9
version: 0.6.1+10

flutter:
plugin:
Expand Down