Reputation: 11259
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.
Upvotes: 7
Views: 8962
Reputation: 205
I'm a bit late at the party, but 4 years later, leancode made an image transformer for transforming assets images to webp. Search on pub. I looked briefly at the source code, it seems the github action is copying the cwebp executable. They communicated with it via dart:ffi. Maybe this can be leveraged in order to create an on demand conversion to webp, not just on your assets. https://github.com/leancodepl/flutter_webp
Upvotes: 0
Reputation: 116
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
Upvotes: 10