Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 9a3a77e

Browse files
authored
[image_picker] Fix images changing to incorrect orientation (#7187)
* fix orientation issue * update changelog * add test * fix formatting
1 parent 5304424 commit 9a3a77e

File tree

7 files changed

+62
-6
lines changed

7 files changed

+62
-6
lines changed

packages/image_picker/image_picker_ios/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.6+8
2+
3+
* Fixes issue with images sometimes changing to incorrect orientation.
4+
15
## 0.8.6+7
26

37
* Fixes issue where GIF file would not animate without `Photo Library Usage` permissions. Fixes issue where PNG and GIF files were converted to JPG, but only when they are do not have `Photo Library Usage` permissions.

packages/image_picker/image_picker_ios/example/ios/Runner.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
680049382280F2B9006DD6AB /* pngImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 680049352280F2B8006DD6AB /* pngImage.png */; };
1919
680049392280F2B9006DD6AB /* jpgImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 680049362280F2B8006DD6AB /* jpgImage.jpg */; };
2020
6801C8392555D726009DAF8D /* ImagePickerFromGalleryUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6801C8382555D726009DAF8D /* ImagePickerFromGalleryUITests.m */; };
21+
782C2B45299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */; };
22+
782C2B46299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */; };
2123
7865C5E12941326F0010E17F /* bmpImage.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 7865C5E02941326F0010E17F /* bmpImage.bmp */; };
2224
7865C5E22941326F0010E17F /* bmpImage.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 7865C5E02941326F0010E17F /* bmpImage.bmp */; };
2325
7865C5E4294132D50010E17F /* svgImage.svg in Resources */ = {isa = PBXBuildFile; fileRef = 7865C5E3294132D50010E17F /* svgImage.svg */; };
@@ -95,6 +97,7 @@
9597
6801C83A2555D726009DAF8D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9698
68B9AF71243E4B3F00927CE4 /* ImagePickerPluginTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImagePickerPluginTests.m; sourceTree = "<group>"; };
9799
68F4B463228B3AB500C25614 /* PhotoAssetUtilTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PhotoAssetUtilTests.m; sourceTree = "<group>"; };
100+
782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = jpgImageWithRightOrientation.jpg; sourceTree = "<group>"; };
98101
7865C5E02941326F0010E17F /* bmpImage.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = bmpImage.bmp; sourceTree = "<group>"; };
99102
7865C5E3294132D50010E17F /* svgImage.svg */ = {isa = PBXFileReference; lastKnownFileType = text; path = svgImage.svg; sourceTree = "<group>"; };
100103
7865C5E62941374F0010E17F /* heicImage.heic */ = {isa = PBXFileReference; lastKnownFileType = file; path = heicImage.heic; sourceTree = "<group>"; };
@@ -169,6 +172,7 @@
169172
680049282280E33D006DD6AB /* TestImages */ = {
170173
isa = PBXGroup;
171174
children = (
175+
782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */,
172176
86E9A88F272747B90017E6E0 /* webpImage.webp */,
173177
9FC8F0E8229FA49E00C8D58F /* gifImage.gif */,
174178
680049362280F2B8006DD6AB /* jpgImage.jpg */,
@@ -398,6 +402,7 @@
398402
86E9A894272754A30017E6E0 /* webpImage.webp in Resources */,
399403
86E9A895272769130017E6E0 /* pngImage.png in Resources */,
400404
7865C5FC294157BC0010E17F /* icnsImage.icns in Resources */,
405+
782C2B45299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */,
401406
86E9A896272769150017E6E0 /* jpgImage.jpg in Resources */,
402407
7865C5ED294137AB0010E17F /* tiffImage.tiff in Resources */,
403408
);
@@ -409,6 +414,7 @@
409414
files = (
410415
9FC8F0EC229FA68500C8D58F /* gifImage.gif in Resources */,
411416
7865C5EE294137AB0010E17F /* tiffImage.tiff in Resources */,
417+
782C2B46299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */,
412418
7865C5E82941374F0010E17F /* heicImage.heic in Resources */,
413419
7865C5FD294157BC0010E17F /* icnsImage.icns in Resources */,
414420
680049382280F2B9006DD6AB /* pngImage.png in Resources */,

packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m

+13-4
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@ - (void)testScaledImage_ShouldBeScaledWithNoMetadata {
3636
}
3737

3838
- (void)testScaledImage_ShouldBeCorrectRotation {
39-
UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData];
39+
NSURL *imageURL =
40+
[[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation"
41+
withExtension:@"jpg"];
42+
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
43+
UIImage *image = [UIImage imageWithData:imageData];
44+
XCTAssertEqual(image.size.width, 130);
45+
XCTAssertEqual(image.size.height, 174);
46+
XCTAssertEqual(image.imageOrientation, UIImageOrientationRight);
47+
4048
UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image
41-
maxWidth:@3
42-
maxHeight:@2
49+
maxWidth:@10
50+
maxHeight:@10
4351
isMetadataAvailable:YES];
44-
52+
XCTAssertEqual(newImage.size.width, 10);
53+
XCTAssertEqual(newImage.size.height, 7);
4554
XCTAssertEqual(newImage.imageOrientation, UIImageOrientationUp);
4655
}
4756

packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m

+37
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,43 @@ - (void)testSaveHEICImage API_AVAILABLE(ios(14)) {
101101
[self verifySavingImageWithPickerResult:result fullMetadata:YES withExtension:@"jpg"];
102102
}
103103

104+
- (void)testSaveWithOrientation API_AVAILABLE(ios(14)) {
105+
NSURL *imageURL =
106+
[[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation"
107+
withExtension:@"jpg"];
108+
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL];
109+
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider];
110+
111+
XCTestExpectation *pathExpectation = [self expectationWithDescription:@"Path was created"];
112+
XCTestExpectation *operationExpectation =
113+
[self expectationWithDescription:@"Operation completed"];
114+
115+
FLTPHPickerSaveImageToPathOperation *operation = [[FLTPHPickerSaveImageToPathOperation alloc]
116+
initWithResult:result
117+
maxHeight:@10
118+
maxWidth:@10
119+
desiredImageQuality:@100
120+
fullMetadata:NO
121+
savedPathBlock:^(NSString *savedPath, FlutterError *error) {
122+
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:savedPath]);
123+
124+
// Ensure image retained it's orientation data.
125+
XCTAssertEqualObjects([NSURL URLWithString:savedPath].pathExtension, @"jpg");
126+
UIImage *image = [UIImage imageWithContentsOfFile:savedPath];
127+
XCTAssertEqual(image.imageOrientation, UIImageOrientationRight);
128+
XCTAssertEqual(image.size.width, 7);
129+
XCTAssertEqual(image.size.height, 10);
130+
[pathExpectation fulfill];
131+
}];
132+
operation.completionBlock = ^{
133+
[operationExpectation fulfill];
134+
};
135+
136+
[operation start];
137+
[self waitForExpectationsWithTimeout:30 handler:nil];
138+
XCTAssertTrue(operation.isFinished);
139+
}
140+
104141
- (void)testSaveICNSImage API_AVAILABLE(ios(14)) {
105142
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"icnsImage"
106143
withExtension:@"icns"];

packages/image_picker/image_picker_ios/ios/Classes/FLTPHPickerSaveImageToPathOperation.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ - (void)processImage:(NSData *)pickerImageData API_AVAILABLE(ios(14)) {
135135
localImage = [FLTImagePickerImageUtil scaledImage:localImage
136136
maxWidth:self.maxWidth
137137
maxHeight:self.maxHeight
138-
isMetadataAvailable:originalAsset != nil];
138+
isMetadataAvailable:YES];
139139
}
140140
if (originalAsset) {
141141
void (^resultHandler)(NSData *imageData, NSString *dataUTI, NSDictionary *info) =

packages/image_picker/image_picker_ios/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: image_picker_ios
22
description: iOS implementation of the image_picker plugin.
33
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
5-
version: 0.8.6+7
5+
version: 0.8.6+8
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

0 commit comments

Comments
 (0)