Karel Debedts
Karel Debedts

Reputation: 5788

Flutter: make image even smaller

I'm making a flutter app that uploads images to firebase storage.

To make the image not too large, i compress them with the folowing code

  compressImage() async {
    final tempDir = await getTemporaryDirectory();
    final path = tempDir.path;
    Im.Image imageFile = Im.decodeImage(file.readAsBytesSync());
    final compressedImageFile = File('$path/img_$postID.jpg')
      ..writeAsBytesSync(Im.encodeJpg(imageFile, quality: 50));

    setState(() {
      file = compressedImageFile;
    });
  }

If I upload photos with an android device, it's sometimes 500kb, sometimes 200kb .... But with the apple ios simulator stock photos, the size is still arround 1 MB, is there an option to get much smaller images, like 500kb max?

Thank you!

Upvotes: 0

Views: 437

Answers (1)

Karel Debedts
Karel Debedts

Reputation: 5788

Fixed it with the flutter image package. Resized the image, then the file size gets much smaller.

Upvotes: 3

Related Questions