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

[image_picker] Fix images changing to incorrect orientation #7187

Merged
merged 4 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -95,6 +97,7 @@
6801C83A2555D726009DAF8D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
68B9AF71243E4B3F00927CE4 /* ImagePickerPluginTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImagePickerPluginTests.m; sourceTree = "<group>"; };
68F4B463228B3AB500C25614 /* PhotoAssetUtilTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PhotoAssetUtilTests.m; sourceTree = "<group>"; };
782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = jpgImageWithRightOrientation.jpg; sourceTree = "<group>"; };
7865C5E02941326F0010E17F /* bmpImage.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = bmpImage.bmp; sourceTree = "<group>"; };
7865C5E3294132D50010E17F /* svgImage.svg */ = {isa = PBXFileReference; lastKnownFileType = text; path = svgImage.svg; sourceTree = "<group>"; };
7865C5E62941374F0010E17F /* heicImage.heic */ = {isa = PBXFileReference; lastKnownFileType = file; path = heicImage.heic; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +172,7 @@
680049282280E33D006DD6AB /* TestImages */ = {
isa = PBXGroup;
children = (
782C2B44299ECE33008DC703 /* jpgImageWithRightOrientation.jpg */,
86E9A88F272747B90017E6E0 /* webpImage.webp */,
9FC8F0E8229FA49E00C8D58F /* gifImage.gif */,
680049362280F2B8006DD6AB /* jpgImage.jpg */,
Expand Down Expand Up @@ -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 */,
);
Expand All @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ - (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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,43 @@ - (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"];
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down