Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.7.6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's no publish API change, it should be 0.7.5+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


* Fixes a rotation problem where Select Photos limited access is chosen but the image that is picked
is not included selected photos and image is scaled.

## 0.7.5

* Fixes an issue where image rotation is wrong when Select Photos chose and image is scaled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ NS_ASSUME_NONNULL_BEGIN

+ (UIImage *)scaledImage:(UIImage *)image
maxWidth:(NSNumber *)maxWidth
maxHeight:(NSNumber *)maxHeight;
maxHeight:(NSNumber *)maxHeight
metadataAvailability:(BOOL)metadataAvailability;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's a bool, the name should be more like a bool, maybe isMetadataAvailable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


// Resize all gif animation frames.
+ (GIFInfo *)scaledGIFImage:(NSData *)data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ @implementation FLTImagePickerImageUtil : NSObject

+ (UIImage *)scaledImage:(UIImage *)image
maxWidth:(NSNumber *)maxWidth
maxHeight:(NSNumber *)maxHeight {
maxHeight:(NSNumber *)maxHeight
metadataAvailability:(BOOL)metadataAvailability {
double originalWidth = image.size.width;
double originalHeight = image.size.height;

Expand Down Expand Up @@ -69,6 +70,19 @@ + (UIImage *)scaledImage:(UIImage *)image
}
}

if (!metadataAvailability) {
UIImage *imageToScale = [UIImage imageWithCGImage:image.CGImage
scale:1
orientation:image.imageOrientation];

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

UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}

// Scaling the image always rotate itself based on the current imageOrientation of the original
// Image. Set to orientationUp for the orignal image before scaling, so the scaled image doesn't
// mess up with the pixels.
Expand Down Expand Up @@ -130,7 +144,7 @@ + (GIFInfo *)scaledGIFImage:(NSData *)data
}

UIImage *image = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:UIImageOrientationUp];
image = [self scaledImage:image maxWidth:maxWidth maxHeight:maxHeight];
image = [self scaledImage:image maxWidth:maxWidth maxHeight:maxHeight metadataAvailability:YES];

[images addObject:image];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,17 @@ - (void)picker:(PHPickerViewController *)picker
if (image != nil) {
__block UIImage *localImage = image;
dispatch_async(dispatch_get_main_queue(), ^{
if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
localImage = [FLTImagePickerImageUtil scaledImage:localImage
maxWidth:maxWidth
maxHeight:maxHeight];
}

PHAsset *originalAsset =
[FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:result];

if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
localImage =
[FLTImagePickerImageUtil scaledImage:localImage
maxWidth:maxWidth
maxHeight:maxHeight
metadataAvailability:originalAsset == nil ? NO : YES];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can simply be metadataAvailability:originalAsset != nil];

ditto below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

}

if (!originalAsset) {
// Image picked without an original asset (e.g. User took a photo directly)
[self saveImageWithPickerInfo:nil
Expand Down Expand Up @@ -449,11 +451,15 @@ - (void)imagePickerController:(UIImagePickerController *)picker
NSNumber *imageQuality = [_arguments objectForKey:@"imageQuality"];
NSNumber *desiredImageQuality = [self getDesiredImageQuality:imageQuality];

PHAsset *originalAsset = [FLTImagePickerPhotoAssetUtil getAssetFromImagePickerInfo:info];

if (maxWidth != (id)[NSNull null] || maxHeight != (id)[NSNull null]) {
image = [FLTImagePickerImageUtil scaledImage:image maxWidth:maxWidth maxHeight:maxHeight];
image = [FLTImagePickerImageUtil scaledImage:image
maxWidth:maxWidth
maxHeight:maxHeight
metadataAvailability:originalAsset == nil ? NO : YES];
}

PHAsset *originalAsset = [FLTImagePickerPhotoAssetUtil getAssetFromImagePickerInfo:info];
if (!originalAsset) {
// Image picked without an original asset (e.g. User took a photo directly)
[self saveImageWithPickerInfo:info image:image imageQuality:desiredImageQuality];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ @implementation ImageUtilTests

- (void)testScaledImage_ShouldBeScaled {
UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData];
UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image maxWidth:@3 maxHeight:@2];
UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image
maxWidth:@3
maxHeight:@2
metadataAvailability:YES];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also test the scenario with no meta data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


XCTAssertEqual(newImage.size.width, 3);
XCTAssertEqual(newImage.size.height, 2);
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker
description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker
version: 0.7.5
version: 0.7.6

flutter:
plugin:
Expand Down