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

Conversation

@AmolGangadhare
Copy link
Contributor

@AmolGangadhare AmolGangadhare commented Jul 24, 2019

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

Copy link
Contributor

@cyanglaz cyanglaz left a 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"];

Copy link
Contributor

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

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

userInfo:nil];
}

// Commenting as of now as JPEG conversion is done by default
Copy link
Contributor

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.

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

/// 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
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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));

Copy link
Contributor Author

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.

Copy link
Contributor

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!

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, added checks in Android and iOS to check for null

imageQuality = 100;
}

if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
Copy link
Contributor

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.

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

'source': 0,
'maxWidth': null,
'maxHeight': null,
'imageQuality': 100
Copy link
Contributor

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

Copy link
Contributor Author

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

@cyanglaz cyanglaz self-assigned this Jul 24, 2019
@cyanglaz cyanglaz added the submit queue The Flutter team is in the process of landing this PR. label Jul 24, 2019
Copy link
Contributor

@cyanglaz cyanglaz left a 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");
Copy link
Contributor

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

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

imageQuality = @1;
}

if (imageQuality.intValue < 0 || imageQuality.intValue > 100) {
Copy link
Contributor

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.

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

Copy link
Contributor

@cyanglaz cyanglaz left a 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!

Copy link
Contributor

@cyanglaz cyanglaz left a 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.

@@ -1,3 +1,8 @@
## 0.6.0+18
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

@cyanglaz
Copy link
Contributor

It seems some java tests are failing.

@cyanglaz cyanglaz added in review and removed submit queue The Flutter team is in the process of landing this PR. labels Jul 29, 2019
@AmolGangadhare
Copy link
Contributor Author

@cyanglaz I've merged code and updated test cases

Copy link
Contributor

@cyanglaz cyanglaz left a 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 :)

@cyanglaz cyanglaz added the submit queue The Flutter team is in the process of landing this PR. label Jul 30, 2019
@AmolGangadhare
Copy link
Contributor Author

LGTM! I edited the doc a little bit hope you don't mind :)

Not at all. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes submit queue The Flutter team is in the process of landing this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants