-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker_for_web] Added support for maxWidth, maxHeight and imageQuality #4389
[image_picker_for_web] Added support for maxWidth, maxHeight and imageQuality #4389
Conversation
Implementation is based on this : https://labs.madisoft.it/javascript-image-compression-and-resizing/ There are some limitations in this. |
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 contribution @balvinderz! I think that this one is a little bit too green, and it needs some changes to the approach to make this more modular and testable!
In my opinion, the image resizing code should be extracted from the ImagePickerPlugin
class completely. The only thing the plugin knows about resizing images is that it has an instance of an ImageResizer
object that accepts and returns XFile
instances.
I think the following steps are needed:
- Create a
ImageResizer
component that deals with images inXFile
instances, and resizes them according to the parameters passed by the user.- 99% of the code of this component already exists in the
_getCompressedUri
and_calculateSize
methods. Having your own object will allow you to design it more carefully.
- 99% of the code of this component already exists in the
- Have an instance of that
ImageResizer
inside of theImagePickerPlugin
, so it can be:- Used when needed to resize images (normal operation)
- Injectable from tests so it can be mocked out if needed (testability)
- Use the
ImageResizer
in thepickImage
/pickImages
methods, if the user wants a resized output- Do not pass the image resizing parameters (
maxWidth
,maxHeight
,imageQuality
) to the generic methods that pick files and convert them to a XFile!
- Do not pass the image resizing parameters (
- Unit tests for the new
ImageResizer
component - Unit tests for the new resize images (when the correct parameters are passed) feature.
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart
Outdated
Show resolved
Hide resolved
…gins into compress_file_web
I think I have done all the steps that are mentioned in this. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I've rebased this branch with the latest master, there was a small breakage in CI that required the latest code to pass. |
(It's too late to land this. I'll merge on monday.) |
Thanks for the dash @ditman 😄 |
@balvinderz highly deserved! ;) |
Because of a problem in our CI, this had to be released manually (I just did). This should now be available to everybody from pub. |
* master: [webview] Fix typos in the README (flutter#4249) [google_sign_in] add serverAuthCode to GoogleSignInAccount (flutter#4180) [ci] Update macOS Cirrus image to Xcode 13 (flutter#4429) [shared_preferences] Switch to new analysis options (flutter#4384) [flutter_plugin_android_lifecycle] remove placeholder dart file (flutter#4413) [camera] Run iOS methods on UI thread by default (flutter#4140) [ci] Always run all `format` steps (flutter#4427) [flutter_plugin_tools] Fix license-check on Windows (flutter#4425) [google_maps_flutter] Clean Java test, consolidate Marker example. (flutter#4400) [image_picker][android] suppress unchecked warning (flutter#4408) [ci] Replace Firebase Test Lab deprecated Pixel 4 device with Pixel 5 (flutter#4436) [image_picker_for_web] Added support for maxWidth, maxHeight and imageQuality (flutter#4389) Bump compileSdkVersion to 31 (flutter#4432) [camera] Update [CameraOrientationTests testOrientationNotifications] unit test to work on Xcode 13 (flutter#4426) Update integration_test README (flutter#3824) [webview_flutter] Adjust test URLs again (flutter#4407) [google_sign_in] Add serverAuthCode attribute to google_sign_in_platform_interface user data (flutter#4179) [camera] Add filter for unsupported cameras on Android (flutter#4418)
* master: [webview] Fix typos in the README (flutter#4249) [google_sign_in] add serverAuthCode to GoogleSignInAccount (flutter#4180) [ci] Update macOS Cirrus image to Xcode 13 (flutter#4429) [shared_preferences] Switch to new analysis options (flutter#4384) [flutter_plugin_android_lifecycle] remove placeholder dart file (flutter#4413) [camera] Run iOS methods on UI thread by default (flutter#4140) [ci] Always run all `format` steps (flutter#4427) [flutter_plugin_tools] Fix license-check on Windows (flutter#4425) [google_maps_flutter] Clean Java test, consolidate Marker example. (flutter#4400) [image_picker][android] suppress unchecked warning (flutter#4408) [ci] Replace Firebase Test Lab deprecated Pixel 4 device with Pixel 5 (flutter#4436) [image_picker_for_web] Added support for maxWidth, maxHeight and imageQuality (flutter#4389) Bump compileSdkVersion to 31 (flutter#4432) [camera] Update [CameraOrientationTests testOrientationNotifications] unit test to work on Xcode 13 (flutter#4426) Update integration_test README (flutter#3824) [webview_flutter] Adjust test URLs again (flutter#4407) [google_sign_in] Add serverAuthCode attribute to google_sign_in_platform_interface user data (flutter#4179) [camera] Add filter for unsupported cameras on Android (flutter#4418) # Conflicts: # packages/webview_flutter/webview_flutter/CHANGELOG.md # packages/webview_flutter/webview_flutter/pubspec.yaml
* master: (364 commits) Use OpenJDK 11 in CI jobs (flutter#4419) [google_sign_in] remove the commented out code in tests (flutter#4442) [webview] Fix typos in the README (flutter#4249) [google_sign_in] add serverAuthCode to GoogleSignInAccount (flutter#4180) [ci] Update macOS Cirrus image to Xcode 13 (flutter#4429) [shared_preferences] Switch to new analysis options (flutter#4384) [flutter_plugin_android_lifecycle] remove placeholder dart file (flutter#4413) [camera] Run iOS methods on UI thread by default (flutter#4140) [ci] Always run all `format` steps (flutter#4427) [flutter_plugin_tools] Fix license-check on Windows (flutter#4425) [google_maps_flutter] Clean Java test, consolidate Marker example. (flutter#4400) [image_picker][android] suppress unchecked warning (flutter#4408) [ci] Replace Firebase Test Lab deprecated Pixel 4 device with Pixel 5 (flutter#4436) [image_picker_for_web] Added support for maxWidth, maxHeight and imageQuality (flutter#4389) Bump compileSdkVersion to 31 (flutter#4432) [camera] Update [CameraOrientationTests testOrientationNotifications] unit test to work on Xcode 13 (flutter#4426) Update integration_test README (flutter#3824) [webview_flutter] Adjust test URLs again (flutter#4407) [google_sign_in] Add serverAuthCode attribute to google_sign_in_platform_interface user data (flutter#4179) [camera] Add filter for unsupported cameras on Android (flutter#4418) ... # Conflicts: # packages/google_maps_flutter/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java
Adds support for maxWidth, maxHeight and imageQuality in image_picker_for_web
Fixes flutter/flutter#78170
Pre-launch Checklist
dart format
.)[shared_preferences]
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.