image_picker: compressing is not supported for type PNG. How to compress the image files with extension .png?
Asked Answered
V

1

1

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.
Vivanvivarium answered 26/4, 2020 at 5:33 Comment(5)
JPEG is a lossy format - it discards less important aspects of your image to make it smaller. PNG is lossless - it retains all the information from your original picture so lossy compression is not an option.Skylar
Can we rename png image to jpg before conversion ? Is that possible?Vivanvivarium
You can't "rename" it because PNG files and JPEG files have entirely different contents. You could "convert" it from PNG to JPEG but then you might get new issues because JPEGs cannot contain transparency so your images would immediately all become opaque. Convert from PNG to JPEG with ImageMagick in Terminal magick input.png output.jpgSkylar
Sorry, I want to convert the images for my dart project.Vivanvivarium
any update on this?Casket
S
0

Base from the error, image_picker doesn't support png when compressing or changing the image quality. You can use flutter_image_compress plugin which has support for PNG format.

Spartan answered 26/6, 2023 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.