simple_native_image_compress 1.0.1 simple_native_image_compress: ^1.0.1 copied to clipboard
A simple native image compression library for Flutter that supports Windows and Linux as well
simple_native_image_compress #
A simple native image compression library for Flutter written in rust using flutter_rust_bridge and image
Why? #
- 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.
What does it do? #
- If path for an image file is given, it will resize and return Jpeg/WebP image as Uint8List.
Prerequisite #
- Rust
- Android NDK for Android
Example #
Call Library as a Singleton #
final _compress = SimpleNativeImageCompress();
"contain" will make the image fit into the given max width/height. #
try{
final bytes = await _compress.contain(
filePath: yourFilePath,
compressFormat: CompressFormat.Jpeg,
quality: 90,
maxWidth: 512,
maxHeight: 512,
);
} catch (e) {
print(e);
}
"fitWidth" will make the image fit into the given max width. #
try{
final bytes = await _compress.fitWidth(
filePath: yourFilePath,
compressFormat: CompressFormat.WebP,
maxWidth: 512,
);
} catch (e) {
print(e);
}
"fitHeight" will make the image fit into the given max height. #
try{
final bytes = await _compress.fitHeight(
filePath: yourFilePath,
compressFormat: CompressFormat.WebP,
maxHeight: 512,
);
} catch (e) {
print(e);
}
Default values #
- Default value for width and/or height is 1024 px
- Default value for Jpeg quality is 80 (For webP Quality does nothing)
Supported Formats #
- Jpeg
- WebP
Miscellaneous #
- May run slow on debug mode, but it is fine with release mode
TODO #
Since I work on this on my spare time, I don't know when the TODO list will be completed.