native_image_compress
Compress images to JPEG, PNG, WebP, HEIC, or AVIF using the platform's native encoders.
Platform support
| Android | iOS | Linux | macOS | Web | Windows | |
|---|---|---|---|---|---|---|
| Support | SDK 28+ | 15.0+ | soon | 12.0+ | soon | soon |
| JPEG | ✅ | ✅ | ✅ | |||
| PNG | ✅ | ✅ | ✅ | |||
| WebP | ✅ | ❌ | ❌ | |||
| HEIC | ✅ | ✅ | ✅ | |||
| AVIF | ⚠️ | ❌ | ❌ |
Installation
flutter pub add native_image_compress
Android
This plugin requires minSdk 28, raise it in android/app/build.gradle.kts:
android {
defaultConfig {
minSdk = 28
}
}
AVIF support
AVIF encoding requires the device to have an AV1 hardware or software encoder registered.
Usage
import 'package:native_image_compress/image_compress.dart';
final jpeg = await compressToJpeg(originalBytes);
final png = await compressToPng(originalBytes);
final webp = await compressToWebp(originalBytes);
final heic = await compressToHeic(originalBytes);
final avif = await compressToAvif(originalBytes);
Quality, Crop and resize
Every compressTo* function accepts optional quality, cropOptions and resizeOptions:
final result = await compressToJpeg(
originalBytes,
quality: 80,
cropOptions: CropOptions(x: 0, y: 0, width: 800, height: 600),
resizeOptions: ResizeOptions(maxWidth: 1080, maxHeight: 1080),
);