Reputation: 1618
I am working with an APIs which is throwing error when image is greater than 5MB. Now I want to compress the size of image if image size is greater than 5MB then it should compress that to 5MB. Is there any way to do that other than mentioned method
ImagePicker.pickImage(source: picker.ImageSource.gallery,imageQuality: 50)
or how exactly imageQuality
works If you know the exact behavior then please mention that also.
Thanks!
Upvotes: 4
Views: 1159
Reputation: 1857
Check the documentation for the pickImage method.
If specified, the image will be at most
maxWidth
wide andmaxHeight
tall. Otherwise, the image will be returned at its original width and height. TheimageQuality
argument modifies the quality of the image, ranging from 0-100 where 100 is the original/max quality. IfimageQuality
is null, the image with the original quality will be returned. Compression is only supported for certain image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked, a warning message will be logged.
Upvotes: 0
Reputation: 520
The imageQuality argument modifies the quality of the image, ranging from 0-100 where 100 is the original/max quality. If imageQuality is null, the image with the original quality will be returned. Compression is only supported for certain image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked, a warning message will be logged.
https://pub.dev/documentation/image_picker/latest/image_picker/ImagePicker/pickImage.html
Upvotes: 2
Reputation: 327
As of my solution try to use SVG image instead of jpg or png it may help you to reduce size. If You don't find solution then ping me we will try to solve the issue. SVG is highest quality images because it draw by pixels to pixels.
Upvotes: 1
Reputation: 452
You can use the flutter_image_compress dependency.
Look this example: https://pub.dev/packages/flutter_image_compress
Upvotes: 1