From 4d1d166607ae2f0d9427b0cad471c490afc47704 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Thu, 16 Feb 2023 10:19:07 -0600 Subject: [PATCH 1/4] fix orientation issue --- .../ios/Classes/FLTPHPickerSaveImageToPathOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker_ios/ios/Classes/FLTPHPickerSaveImageToPathOperation.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTPHPickerSaveImageToPathOperation.m index efcbdbeec897..80e03ddd6578 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTPHPickerSaveImageToPathOperation.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTPHPickerSaveImageToPathOperation.m @@ -135,7 +135,7 @@ - (void)processImage:(NSData *)pickerImageData API_AVAILABLE(ios(14)) { localImage = [FLTImagePickerImageUtil scaledImage:localImage maxWidth:self.maxWidth maxHeight:self.maxHeight - isMetadataAvailable:originalAsset != nil]; + isMetadataAvailable:YES]; } if (originalAsset) { void (^resultHandler)(NSData *imageData, NSString *dataUTI, NSDictionary *info) = From b1eced59139c3b14bea2bcb338fae0d84c2e68fc Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Thu, 16 Feb 2023 10:39:42 -0600 Subject: [PATCH 2/4] update changelog --- packages/image_picker/image_picker_ios/CHANGELOG.md | 4 ++++ packages/image_picker/image_picker_ios/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker_ios/CHANGELOG.md b/packages/image_picker/image_picker_ios/CHANGELOG.md index b75e6333b94e..dbd5160edd7d 100644 --- a/packages/image_picker/image_picker_ios/CHANGELOG.md +++ b/packages/image_picker/image_picker_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.6+8 + +* Fixes issue with images sometimes changing to incorrect orientation. + ## 0.8.6+7 * 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. diff --git a/packages/image_picker/image_picker_ios/pubspec.yaml b/packages/image_picker/image_picker_ios/pubspec.yaml index 1f4e2af4cb96..b188055087c7 100755 --- a/packages/image_picker/image_picker_ios/pubspec.yaml +++ b/packages/image_picker/image_picker_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: image_picker_ios description: iOS implementation of the image_picker plugin. repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22 -version: 0.8.6+7 +version: 0.8.6+8 environment: sdk: ">=2.14.0 <3.0.0" From 7d15e9c6aebdb2058a0fb16c1263c11490e7a6de Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Thu, 16 Feb 2023 15:00:47 -0600 Subject: [PATCH 3/4] add test --- .../ios/Runner.xcodeproj/project.pbxproj | 6 +++ .../example/ios/RunnerTests/ImageUtilTests.m | 16 ++++++-- .../PickerSaveImageToPathOperationTests.m | 36 ++++++++++++++++++ .../jpgImageWithRightOrientation.jpg | Bin 0 -> 3375 bytes 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 packages/image_picker/image_picker_ios/example/ios/TestImages/jpgImageWithRightOrientation.jpg diff --git a/packages/image_picker/image_picker_ios/example/ios/Runner.xcodeproj/project.pbxproj b/packages/image_picker/image_picker_ios/example/ios/Runner.xcodeproj/project.pbxproj index 2c97bd1d667f..ddbc856d6aa7 100644 --- a/packages/image_picker/image_picker_ios/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/image_picker/image_picker_ios/example/ios/Runner.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 680049382280F2B9006DD6AB /* pngImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 680049352280F2B8006DD6AB /* pngImage.png */; }; 680049392280F2B9006DD6AB /* jpgImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 680049362280F2B8006DD6AB /* jpgImage.jpg */; }; 6801C8392555D726009DAF8D /* ImagePickerFromGalleryUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6801C8382555D726009DAF8D /* ImagePickerFromGalleryUITests.m */; }; + 782C2B45299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */; }; + 782C2B46299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */; }; 7865C5E12941326F0010E17F /* bmpImage.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 7865C5E02941326F0010E17F /* bmpImage.bmp */; }; 7865C5E22941326F0010E17F /* bmpImage.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 7865C5E02941326F0010E17F /* bmpImage.bmp */; }; 7865C5E4294132D50010E17F /* svgImage.svg in Resources */ = {isa = PBXBuildFile; fileRef = 7865C5E3294132D50010E17F /* svgImage.svg */; }; @@ -95,6 +97,7 @@ 6801C83A2555D726009DAF8D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 68B9AF71243E4B3F00927CE4 /* ImagePickerPluginTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImagePickerPluginTests.m; sourceTree = ""; }; 68F4B463228B3AB500C25614 /* PhotoAssetUtilTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PhotoAssetUtilTests.m; sourceTree = ""; }; + 782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = jpgImageWithRightOrientation.jpg; sourceTree = ""; }; 7865C5E02941326F0010E17F /* bmpImage.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = bmpImage.bmp; sourceTree = ""; }; 7865C5E3294132D50010E17F /* svgImage.svg */ = {isa = PBXFileReference; lastKnownFileType = text; path = svgImage.svg; sourceTree = ""; }; 7865C5E62941374F0010E17F /* heicImage.heic */ = {isa = PBXFileReference; lastKnownFileType = file; path = heicImage.heic; sourceTree = ""; }; @@ -169,6 +172,7 @@ 680049282280E33D006DD6AB /* TestImages */ = { isa = PBXGroup; children = ( + 782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */, 86E9A88F272747B90017E6E0 /* webpImage.webp */, 9FC8F0E8229FA49E00C8D58F /* gifImage.gif */, 680049362280F2B8006DD6AB /* jpgImage.jpg */, @@ -398,6 +402,7 @@ 86E9A894272754A30017E6E0 /* webpImage.webp in Resources */, 86E9A895272769130017E6E0 /* pngImage.png in Resources */, 7865C5FC294157BC0010E17F /* icnsImage.icns in Resources */, + 782C2B45299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */, 86E9A896272769150017E6E0 /* jpgImage.jpg in Resources */, 7865C5ED294137AB0010E17F /* tiffImage.tiff in Resources */, ); @@ -409,6 +414,7 @@ files = ( 9FC8F0EC229FA68500C8D58F /* gifImage.gif in Resources */, 7865C5EE294137AB0010E17F /* tiffImage.tiff in Resources */, + 782C2B46299ECE33008DC703 /* jpgImageWithRightOrientation.jpg in Resources */, 7865C5E82941374F0010E17F /* heicImage.heic in Resources */, 7865C5FD294157BC0010E17F /* icnsImage.icns in Resources */, 680049382280F2B9006DD6AB /* pngImage.png in Resources */, diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m index e449a84b80bb..5d8df31ddc91 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m @@ -36,12 +36,20 @@ - (void)testScaledImage_ShouldBeScaledWithNoMetadata { } - (void)testScaledImage_ShouldBeCorrectRotation { - UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData]; + NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation" + withExtension:@"jpg"]; + NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; + UIImage *image = [UIImage imageWithData:imageData]; + XCTAssertEqual(image.size.width, 130); + XCTAssertEqual(image.size.height, 174); + XCTAssertEqual(image.imageOrientation, UIImageOrientationRight); + UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image - maxWidth:@3 - maxHeight:@2 + maxWidth:@10 + maxHeight:@10 isMetadataAvailable:YES]; - + XCTAssertEqual(newImage.size.width, 10); + XCTAssertEqual(newImage.size.height, 7); XCTAssertEqual(newImage.imageOrientation, UIImageOrientationUp); } diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m index 027e287d1586..5efc99363ba8 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m @@ -101,6 +101,42 @@ - (void)testSaveHEICImage API_AVAILABLE(ios(14)) { [self verifySavingImageWithPickerResult:result fullMetadata:YES withExtension:@"jpg"]; } +- (void)testSaveWithOrientation API_AVAILABLE(ios(14)) { + NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation" + withExtension:@"jpg"]; + NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL]; + PHPickerResult *result = [self createPickerResultWithProvider:itemProvider]; + + XCTestExpectation *pathExpectation = [self expectationWithDescription:@"Path was created"]; + XCTestExpectation *operationExpectation = + [self expectationWithDescription:@"Operation completed"]; + + FLTPHPickerSaveImageToPathOperation *operation = [[FLTPHPickerSaveImageToPathOperation alloc] + initWithResult:result + maxHeight:@10 + maxWidth:@10 + desiredImageQuality:@100 + fullMetadata:NO + savedPathBlock:^(NSString *savedPath, FlutterError *error) { + XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:savedPath]); + + // Ensure image retained it's orientation data. + XCTAssertEqualObjects([NSURL URLWithString:savedPath].pathExtension, @"jpg"); + UIImage *image = [UIImage imageWithContentsOfFile:savedPath]; + XCTAssertEqual(image.imageOrientation, UIImageOrientationRight); + XCTAssertEqual(image.size.width, 7); + XCTAssertEqual(image.size.height, 10); + [pathExpectation fulfill]; + }]; + operation.completionBlock = ^{ + [operationExpectation fulfill]; + }; + + [operation start]; + [self waitForExpectationsWithTimeout:30 handler:nil]; + XCTAssertTrue(operation.isFinished); +} + - (void)testSaveICNSImage API_AVAILABLE(ios(14)) { NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"icnsImage" withExtension:@"icns"]; diff --git a/packages/image_picker/image_picker_ios/example/ios/TestImages/jpgImageWithRightOrientation.jpg b/packages/image_picker/image_picker_ios/example/ios/TestImages/jpgImageWithRightOrientation.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2b3eaf5e294463db3fa77fd19cfa298f38cc671c GIT binary patch literal 3375 zcmdT`dsGu=7QZu-2Ly^d1{W=86tM|ME05Ghwz~o`Jfc8CkosCzKpyc327;)Ztpt?1 zO{*0ZA1rF*74;O)p<>l`J!(~ScZ($vD57o^m5PtH*6OwvJ9}sHK-xo3cmM0n-1&a_ za_{}_{U-DMF4MzY2X9qeVjK_zKmvY%xxv4pT&>FiNJ@fG0B{2V;R_TZ0t9#)3w#a( zq!TZ?@M1#Zupt3RKL^I38+5>P*kepMg^H_SEaxcP3?RgBys(If@G8QN36cV{b3QyQ z%uLuLG7Ny3bVWR5rd+t9LEu;wgK;7tD96mOya}(Nyou4n@+O?oh;gKA72aV-ykU7W zJd3d=C_yX7buLjID%vr>o z0v|V64Q7g%2&4}|`4G%mq7L_&&n3uiHz$}UCMI-q7kPLCNl+BYqxhIFTE4+Kh>?m5ZT;=o*+MYHIw^REOYwD+W~RLo?$p9>l^ zC~vZ2vA4xklA{LpL6~aymKrC0zKK7pw4>C1U(8s9NbJ#b|IojVo z=lw~y-S*N{HrD-T^_%3C@n`Z|Po$Lg2268WjWCLqW*f5bw?WjfEPYWio<&m-t5+54 zS^O8obP*b}@kuQgVJT@_j!N#_lWS#N4uJhczlmkm9$eX^D`PHcMgtwlienEFc)8_uBQ&VM|zO_`% zX$#%Vmyhf0)tqjk?nbuHoLE!XTRu-EsVm>0D)~y4PZLbXATef8nsSmp5gOT^d|evQ zV6L^M5lYImxXBnOZxGiI=LNfKJMS7dnIs3nGOZB_WXrDF#}=wavG?OG(E(KR^a_JA z%*8Rt9Wxp0AiN~o*-k&EKOm-CkJ@&}FZf$|5a#lpyeaEM`gM6tbYY@$G}M`-MwTj#tv@#*yfdokvPU zcL(9E)z4^{l)1UqmezwzaS&IRaM~upqFvPNr0DTX=aB19Ia5;KY-c+*dxsKC*9Z=Q z*62Rtq`WL|-)!e^Be&8cA@*Hhx4pH+Z_Yzf69n_uIQVZzy{neEj?(HG8b`0~`P_Uoo XujyXbU5>g#?Q4=WIXfA9H*@*F9kTcL literal 0 HcmV?d00001 From 83b310460191d094bc4270e1ae9ca7f709eb3f20 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Thu, 16 Feb 2023 15:19:28 -0600 Subject: [PATCH 4/4] fix formatting --- .../example/ios/RunnerTests/ImageUtilTests.m | 5 +++-- .../ios/RunnerTests/PickerSaveImageToPathOperationTests.m | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m index 5d8df31ddc91..1dc807a15dba 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m @@ -36,8 +36,9 @@ - (void)testScaledImage_ShouldBeScaledWithNoMetadata { } - (void)testScaledImage_ShouldBeCorrectRotation { - NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation" - withExtension:@"jpg"]; + NSURL *imageURL = + [[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation" + withExtension:@"jpg"]; NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; UIImage *image = [UIImage imageWithData:imageData]; XCTAssertEqual(image.size.width, 130); diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m index 5efc99363ba8..57ccb86c0060 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m @@ -102,8 +102,9 @@ - (void)testSaveHEICImage API_AVAILABLE(ios(14)) { } - (void)testSaveWithOrientation API_AVAILABLE(ios(14)) { - NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation" - withExtension:@"jpg"]; + NSURL *imageURL = + [[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImageWithRightOrientation" + withExtension:@"jpg"]; NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL]; PHPickerResult *result = [self createPickerResultWithProvider:itemProvider];