flutter_image_compress 0.2.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 92

flutter_image_compress

pub package GitHub GitHub stars

compress image with native code(objc kotlin)

This library can work on android/ios.

why

Q:Dart has image related libraries to compress. Why use native?

A:For reasons unknown, using dart language is not efficient, even in release version, using isolate can not solve the problem.

about android

maybe, you need update your kotlin version to 1.2.71 or higher.

about ios

No problems found at present.

use

dependencies:
  flutter_image_compress: ^0.2.1
import 'package:flutter_image_compress/flutter_image_compress.dart';

use:

see whole example code

  Future<List<int>> testCompressFile(File file) async {
    var result = await FlutterImageCompress.compressWithFile(
      file.absolute.path,
      minWidth: 2300,
      minHeight: 1500,
      quality: 94,
      rotate: 90,
    );
    print(file.lengthSync());
    print(result.length);
    return result;
  }

  Future<File> testCompressAndGetFile(File file, String targetPath) async {
    var result = await FlutterImageCompress.compressAndGetFile(
        file.absolute.path, targetPath,
        quality: 88,
        rotate: 180,
      );

    print(file.lengthSync());
    print(result.lengthSync());

    return result;
  }

  Future<List<int>> testCompressAsset(String assetName) async {
    var list = await FlutterImageCompress.compressAssetImage(
      assetName,
      minHeight: 1920,
      minWidth: 1080,
      quality: 96,
      rotate: 180,
    );

    return list;
  }

  Future<List<int>> testComporessList(List<int> list) async {
    var result = await FlutterImageCompress.compressWithList(
      list,
      minHeight: 1920,
      minWidth: 1080,
      quality: 96,
      rotate: 135,
    );
    print(list.length);
    print(result.length);
    return result;
  }

about List<int>

you maybe need convert List<int> to 'Uint8List'

var u8 = Uint8List.fromList(list)
ImageProvider provider = MemoryImage(Uint8List.fromList(list));

use in Image Widget

    List<int> list = await testCompressFile(file);
    ImageProvider provider = MemoryImage(Uint8List.fromList(list));

    Image(
      image: provider ?? AssetImage("img/img.jpg"),
    ),

write to file

  void writeToFile(List<int> list, String filePath) {
    var file = File(filePath);
    file.writeAsBytes(list, flush: true, mode: FileMode.write);
  }

android build error

Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener.
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:86)
        ...
Caused by: java.lang.AbstractMethodError
        at org.jetbrains.kotlin.gradle.plugin.KotlinPluginKt.resolveSubpluginArtifacts(KotlinPlugin.kt:776)
        ...

see the flutter/flutter/issues#21473

you need edit your kotlin version to 1.2.71+

If flutter supports more platforms (windows, mac, linux, other) in the future and you use this library, propose issue / PR

CHANGELOG

0.2.1

update readme

0.2.0

The version number is updated so that people who can use the higher version of gradle can use it. see pr #8

if android run error, you must update your kotlin'version to 1.2.71+

0.1.4

add optional params rotate

fix bug

update example

0.1.3

fix the ios flutter.h bug

0.1.1

update readme

0.1.0

first version

example/README.md

flutter_image_compress_example

Demonstrates how to use the flutter_image_compress plugin.

Getting Started

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_image_compress: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_image_compress/flutter_image_compress.dart';
  
Version Uploaded Documentation Archive
0.2.1 Nov 6, 2018 Go to the documentation of flutter_image_compress 0.2.1 Download flutter_image_compress 0.2.1 archive
0.2.0 Oct 23, 2018 Go to the documentation of flutter_image_compress 0.2.0 Download flutter_image_compress 0.2.0 archive
0.1.4 Oct 23, 2018 Go to the documentation of flutter_image_compress 0.1.4 Download flutter_image_compress 0.1.4 archive
0.1.3 Sep 28, 2018 Go to the documentation of flutter_image_compress 0.1.3 Download flutter_image_compress 0.1.3 archive
0.1.2 Sep 9, 2018 Go to the documentation of flutter_image_compress 0.1.2 Download flutter_image_compress 0.1.2 archive
0.1.1 Sep 8, 2018 Go to the documentation of flutter_image_compress 0.1.1 Download flutter_image_compress 0.1.1 archive
0.1.0 Sep 8, 2018 Go to the documentation of flutter_image_compress 0.1.0 Download flutter_image_compress 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
83
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Nov 6, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0-dev.7.1.flutter-b99bcfd309
  • pana: 0.12.5
  • Flutter: 0.10.1

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/flutter_image_compress.dart.

Run flutter format to format lib/flutter_image_compress.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8