In order to compress .jpg file this code simply works.
File pickedFile = await ImagePicker.pickImage(source: ImageSource.gallery);
print('Size in kb: -> ' + (pickedFile.lengthSync() / 1000).toString());
File compressedFile = await ImagePicker.pickImage( source: ImageSource.gallery, imageQuality: 50);
print('Size kb: -> ' + (compressedFile.lengthSync() / 1000).toString());
_uploadFile(compressedFile);
But how to compress the image files which have the extension like .png ?
Error:
D/ImageResizer( 6282): image_picker: compressing is not supported for type PNG. Returning the image with original quality
W/ExifInterface( 6282): Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
magick input.png output.jpg
– Skylar