Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compress image size to 5MB in flutter

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!

like image 653
Arslan Kaleem Avatar asked Oct 15 '25 03:10

Arslan Kaleem


2 Answers

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

like image 154
Mofidul Islam Avatar answered Oct 17 '25 17:10

Mofidul Islam


You can use the flutter_image_compress dependency.

Look this example: https://pub.dev/packages/flutter_image_compress

like image 45
NewProgrammer Avatar answered Oct 17 '25 16:10

NewProgrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!