Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : Convert jpg to webp

I want to convert .jpg or .png files to .webp. Unfortunately image package only support webp reading and not writing.

One solution would be to add the linux binary file to flutter (cwebp), but how to execute it smoothly ? I checked and found that this question was asked over 1 year ago and still unanswered

I am open to any suggestion, the end goal is not so much the format in itself but the lowest file size for overall good quality on mobile phone resolution.

like image 888
Antonin GAVREL Avatar asked Jun 12 '20 22:06

Antonin GAVREL


People also ask

Is flutter support WebP?

The Flutter app supports many image formats, such as JPEG, WebP, PNG, GIF, animated WebP/GIF, BMP, and WBMP.

Is WebP better than JPEG?

Conclusion. The study evaluated WebP compression in comparison to JPEG. We observed that the average WebP file size is 25%-34% smaller compared to JPEG file size at equivalent SSIM index. The SSIM vs bpp plots showed that WebP consistently required less bits per pixel than JPEG for the same SSIM index.


1 Answers

Flutter has a compressor package, called flutter_image_compress. It has a compressor for web images.

Future<Uint8List> testComporessList(Uint8List list) async {
    final result = await FlutterImageCompress.compressWithList(
      list,
      minHeight: 1080,
      minWidth: 1080,
      quality: 96,
      rotate: 270,
      format: CompressFormat.webp,
    );
    print(list.length);
    print(result.length);
    return result;
  }

https://pub.dev/packages/flutter_image_compress

like image 116
Emmanuel Vinicius Avatar answered Nov 08 '22 21:11

Emmanuel Vinicius