yekeskin / flutter_avif

A flutter plugin to view and encode avif images.
https://pub.dev/packages/flutter_avif
MIT License
61 stars 17 forks source link

Feature request : Option to change resolution of image while encoding to avif #28

Closed Kevin301099 closed 1 year ago

yekeskin commented 1 year ago

I don't think image manipulation is in the scope of this plugin. You can use a package like image to resize your images.

final asset = await rootBundle.load("assets/fox.jpg");
final inputImage = decodeImage(asset.buffer.asUint8List());
final scaledImage = copyResize(inputImage!, width: 200);
final avifBytes = await encodeAvif(img.encodeBmp(scaledImage));

If the source image is also avif:

final asset = await rootBundle.load("assets/fox.avif");
final codec = SingleFrameAvifCodec(bytes: asset.buffer.asUint8List());
await codec.ready();
final frame = await codec.getNextFrame();
final uiImage = await frame.image.toByteData(format: ImageByteFormat.png);
final inputImage = decodeImage(uiImage!.buffer.asUint8List());
final scaledImage = copyResize(inputImage!, width: 100);
final avifBytes = await encodeAvif(img.encodeBmp(scaledImage));

If it is an animated avif you would have to use MultiFrameAvifCodec and get each frame by calling codec.getNextFrame() then add them to the inputImage you first created.

Kevin301099 commented 1 year ago

ok, thank you