mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 17:28:42 +08:00
[image_picker] Fix images changing to incorrect orientation (#7187)
* fix orientation issue * update changelog * add test * fix formatting
This commit is contained in:

committed by
GitHub

parent
4f30210efa
commit
ae9d10ef55
@ -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.
|
||||
|
@ -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 = "<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>"; };
|
||||
@ -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 */,
|
||||
|
@ -36,12 +36,21 @@
|
||||
}
|
||||
|
||||
- (void)testScaledImage_ShouldBeCorrectRotation {
|
||||
UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData];
|
||||
UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image
|
||||
maxWidth:@3
|
||||
maxHeight:@2
|
||||
isMetadataAvailable:YES];
|
||||
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:@10
|
||||
maxHeight:@10
|
||||
isMetadataAvailable:YES];
|
||||
XCTAssertEqual(newImage.size.width, 10);
|
||||
XCTAssertEqual(newImage.size.height, 7);
|
||||
XCTAssertEqual(newImage.imageOrientation, UIImageOrientationUp);
|
||||
}
|
||||
|
||||
|
@ -101,6 +101,43 @@
|
||||
[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"];
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
@ -135,7 +135,7 @@ 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) =
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user