skip to Main Content

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


  1. ImagePicker()
      .pickImage(
       source: useCamera ? ImageSource.camera : ImageSource.gallery,
       imageQuality: 60)
    

    Hope it will help.

    Login or Signup to reply.
  2. First you can get the image size by following code:

    final bytes = image.readAsBytesSync().lengthInBytes;
    final kb = bytes / 1024;
    final mb = kb / 1024;
    

    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search