-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[image_picker] New feature : pick images with image quality #1896
Conversation
cyanglaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for the contribution. This looks great overall! I left some comments below.
| NSNumber *maxWidth = [_arguments objectForKey:@"maxWidth"]; | ||
| NSNumber *maxHeight = [_arguments objectForKey:@"maxHeight"]; | ||
| NSNumber *imageQuality = [_arguments objectForKey:@"imageQuality"]; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add
if (![ImageQuality isKindOfClass:[NSNumber class]]) {
imageQuality = @1;
} This made the imageQuality an optional parameter and returns 1 to be default. Same on Android
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| userInfo:nil]; | ||
| } | ||
|
|
||
| // Commenting as of now as JPEG conversion is done by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should still keep this check. However, we don't want to crash it anymore. Since the compressing on PNG with quality is not supported. We want to let the plugin users aware of it.
Something like
if (quality && type != FLTImagePickerMIMETypeJPEG) {
NSLog(@"image_picker: compressing is not supported for type %@. Returning the image with original quality");
}
This is mainly to handle when plugin users choose to reduce quality but the user picked a PNG image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| /// original width and height. | ||
| /// The [imageQuality] argument resize the image as per the input, ranging from 0-100 compression. | ||
| /// 0 meaning compress for small size, 100 meaning compress for max quality. | ||
| /// Some formats, like PNG which is loss less, will ignore the quality setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems only apply to iOS? It seems Android can compress PNGs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in android, for PNG(lossless formats) it will ignore the compression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so you are saying Android behaves the same as iOS. Then we can also print a message from Android if user picked a PNG but the quality is set to lower than 100. I think it is a good info for developer when debugging or profiling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, added a log in the Android part, with the same log as in iOS
| throw ArgumentError.value(maxHeight, 'maxHeight cannot be negative'); | ||
| } | ||
|
|
||
| if (null == imageQuality) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make imageQuality optional to reduce unwanted computations.
assert(imageQuality == null || (imageQuality >= 0 && imageQuality <= 100));There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to make imageQuality mandatory? now if imageQuality gets null from a user, replacing it with 100 does not have any impact on image quality, it will return the image as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we don't need to make the imageQuality mandatory. However, I'd like to keep the parameters sent to the platform consistent with what user has passed in the method call, and let the underlying platform handle the case when imageQuality is null.
So the method channel params will look like
{
source:"camera",
imageQuality:null,
}
And from the platform (iOS for example) .
NSNumber *quality = @(1);
if ([argument[@"imageQuality"] isKindOfClass[NSNumber class]]) {
quality = [argument[@"imageQuality] floatValue]/100;
}It is just my personal opinion. Your code works perfectly fine as it is now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, added checks in Android and iOS to check for null
| imageQuality = 100; | ||
| } | ||
|
|
||
| if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this "if" and use the assert I mentioned above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| 'source': 0, | ||
| 'maxWidth': null, | ||
| 'maxHeight': null, | ||
| 'imageQuality': 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add a test for imageQuality is null after making imageQuality an optional param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've added the test for null condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick turn around. Left some more comments.
| // userInfo:nil]; | ||
| // } | ||
| if (quality && type != FLTImagePickerMIMETypeJPEG) { | ||
| NSLog(@"image_picker: compressing is not supported for type %@. Returning the image with original quality"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add argument for type.
NSLog(@"image_picker: compressing is not supported for type %@. Returning the image with original quality", [FLTImagePickerMetaDataUtil imageTypeSuffixFromType:type]});I typed this code on Github site so it might fail compilation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| imageQuality = @1; | ||
| } | ||
|
|
||
| if (imageQuality.intValue < 0 || imageQuality.intValue > 100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it else if. in iOS nil.intValue will return 0 which is not what we wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cyanglaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! CI seems to be complaining about the formatting. Also, please update pubspec and changelog with a new version! Thanks again!
cyanglaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you! Version needs to be updated.
packages/image_picker/CHANGELOG.md
Outdated
| @@ -1,3 +1,8 @@ | |||
| ## 0.6.0+18 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 0.6.1, same in pubspec
https://dart.dev/tools/pub/versioning#semantic-versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated pubspec and changelog with a new version.
|
It seems some java tests are failing. |
|
@cyanglaz I've merged code and updated test cases |
cyanglaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I edited the doc a little bit hope you don't mind :)
Not at all. :) |
Description
Now, user can provide image quality (compression ratio) while picking an image.
The images will be compressed based on the input. 0 meaning compress for small size, 100 meaning compress for max quality.
Related Issues
flutter/flutter/issues/34523
flutter/flutter/issues/36072
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?