搜索插件、代码仓与 APP 分类

GitHub 代码仓SimformSolutionsPvtLtd/fast_image_compress

fast_image_compress

一个允许快速、轻松且高效压缩图像的 Flutter 插件。👌🔝🎉

fast_image_compress 项目封面
星标
31
复刻
1
最近推送(UTC)
2025年5月12日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

Fast Image Compress - Simform LLC.

fast_image_compress

pub package GitHub license

A Flutter plugin that allows you to compress images easily and quickly.

Features

Fast Image Compress can do much more (and we are just getting started)

  • 📱 Supported platform. iOS, Android
  • 🧪 Batch processing. Support batch processing using batchSize
  • 🖼️ Supported image types jpeg, png and heic
  • ⏱ Parallelism. Support parallel image compression

Why fast_image_compress

The following bar graph demonstrates the efficiency of our plugin compared to two other existing packages. The comparison was conducted by compressing one image at a time for various image sizes, measuring the time taken in milliseconds (Y-axis) against the image size in MB (X-axis).

Below are the comparison graphs:

Android iOS

This visual representation highlights the better performance of our plugin in terms of compression speed and efficiency across different image sizes.

Installing

  1. Add dependency to pubspec.yaml
dependencies:
    fast_image_compress: <latest_version>

or run this command:

flutter pub add fast_image_compress
  1. Import the package
import 'package:fast_image_compress/fast_image_compress.dart';

Use as:

See full example

There are several ways to use the library api.


// 1. Compress an image and get Uint8List
Future<Uint8List> compressImage(Uint8List imageData) async {
  final compressedImage = await fastImageCompress.compressImage(
    imageData: imageData,
    quality: 60,
    targetWidth: 400,
    imageQuality: ImageQuality.low,
  );
  return compressedImage;
}

// 2. Compress list of images and get a list of Uint8List
Future<List<Uint8List>> compressMultipleImages(List<Uint8List> imageList) async {
  final result = await fastImageCompress.compressImageList(
    images: imageList,
    quality: 30,
    targetWidth: 800,
    batchSize: 3,
    imageQuality: ImageQuality.low,
  );
  return result;
}
  
// 3. Cancel the compression process
Future<void> _cancelCompression() async {
  await fastImageCompress.cancelCompression();
}

Parameters of compressImage function:

Parameter Name Data type Default Value Description
imageData Uint8List - The image to be compressed
quality int 60 The compression quality percentage
targetWidth int? null The desired width for the compressed image
imageQuality ImageQuality ImageQuality.medium The quality of the image to store after compression

Parameters of compressImage function:

Parameter Name Data type Default Value Description
imageData Uint8List - The image to be compressed
quality int 60 The compression quality percentage
targetWidth int? null The desired width for the compressed image
imageQuality ImageQuality ImageQuality.medium The quality of the image to store after compression
batchSize int 3 The number of images to process simultaneously in a batch

About params

targetWidth

The targetWidth parameter allows you to resize the images to a specific width.

Use this parameter when you need all images to have a uniform width. It is particularly useful for optimizing image processing performance. Recommended to use this parameter when image size or image width is large.

batchSize

The batchSize parameter determines how many images are processed in a single batch.

  • If the image sizes are large (greater than 50 MB), set batchSize to a smaller value to avoid memory issues.
  • If the image sizes are small, you can set a higher value (e.g., 6) for better performance.

To dynamically adjust batchSize based on the number of CPU threads available on the device, you can use the following code:

final maxAvailableCPUThreads = Platform.numberOfProcessors;
final batchSize = maxAvailableCPUThreads > 0 ? maxAvailableCPUThreads ~/ 2 : 1;
imageQuality

The imageQuality parameter controls the quality of the processed images. It has three predefined values:

  • low
  • medium (default)
  • high

Android

You may need to update Kotlin to version 1.5.20 or higher.

About EXIF information

Using this library, the image orientation is maintained.

HEIF(Heic)
Heif on iOS

Only support iOS 11+.

Heif on Android

Only support API 28+.

Note: Requires hardware encoder support, so availability is not guaranteed on all devices running API 28 or higher.

Main Contributors


Rashi Shah

License

MIT License

Copyright (c) 2021 Simform Solutions

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Simform Solutions GitHub avatar
GitHub 作者

Simform Solutions ↗

语言DartKotlinSwiftRubyObjective-C

分类

此仓库发布的插件

使用的依赖

依赖清单 5 项

  • flutter{"sdk":"flutter"}
  • plugin_platform_interface^2.0.2
  • flutter_test开发依赖{"sdk":"flutter"}
  • flutter_lints开发依赖^4.0.0
  • pana开发依赖—

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗