Hello i am using image_picker plugin on flutter and with it i can change the quality of an image from 100 percent to 1. with image quality property.
Some of my uploaded images are 500 kb to 10 mb so some needs compressing and some dont.
So is it possible to check the 100% quality version and if it is less size than 2 mb it stays 100% and we upload the image.
if it is bigger than 2mb drop the quality to 75%.
check the size < 2 mb upload it or >2mb drop to 50 quality.
try it on 25% and 10% and 1% if its still not less than 2mb on 1 percent quality just dont upload it.
there must be a way to do this like even on instagram they try to save the photos on full size but i dont think so that they will still save it on full size if it is bigger than 100mb or something like that right?
and this plugin opens a weird last 40 images page? on the pick file screen why doesnt it open the default gallery app although i use the source: ImageSource.gallery property ?
2
Answers
Hope it will help.
First you can get the image size by following code:
Then you can implement switch cases of if-else statements to implement image compressing functionality.
Also there’s a package called
flutter_image_compress
which can compress your image after you have selected it.Also they have provided various examples for multiple file formats