A simple native image compression library for Flutter written in rust using flutter_rust_bridge, image, cargokit and kamadak-exif
- For some reason, image compression in Dart is slow. Even with isolate.
- There is no native libraries that supports WINDOWS & LINUX when it comes to image compression.
- If path for an image file is given, it will resize and return Jpeg/WebP image as Uint8List.
- Rust
- Android NDK for Android
- Jpeg
- WebP
-
5 types of sampling filters are available and can be selected
- Nearest, // Nearest Neighbor
- Triangle, // Linear Filter (DEFAULT)
- CatmullRom, // Cubic Filter
- Gaussian, // Gaussian Filter
- Lanczos3, // Lanczos with window 3
-
when samplingFilter is null, FilterType.Triangle is set to be default.
-
you can read more about sampling filters here image crate doc
final compress = SimpleNativeImageCompress();try{
final bytes = await compress.contain(
filePath: yourFilePath,
compressFormat: CompressFormat.Jpeg,
quality: 90,
maxWidth: 512,
maxHeight: 512,
samplingFilter: FilterType.Lanczos3
);
} catch (e) {
print(e);
}try{
final bytes = await compress.fitWidth(
filePath: yourFilePath,
compressFormat: CompressFormat.WebP,
maxWidth: 512,
samplingFilter: FilterType.Lanczos3
);
} catch (e) {
print(e);
}try{
final bytes = await compress.fitHeight(
filePath: yourFilePath,
compressFormat: CompressFormat.WebP,
maxHeight: 512,
samplingFilter: FilterType.Lanczos3
);
} catch (e) {
print(e);
}- Default value for width and/or height is 1024 px
- Default value for Jpeg quality is 80 (For webP Quality does nothing)