how to compress image size to 5MB in flutter

203

Solution 1

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

Solution 2

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.

Solution 3

You can use the flutter_image_compress dependency.

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

Share:
203
Arslan Kaleem
Author by

Arslan Kaleem

Updated on January 01, 2023

Comments

  • Arslan Kaleem
    Arslan Kaleem over 1 year

    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!