GithubHelp home page GithubHelp logo

crazecoder / flutter_luban Goto Github PK

View Code? Open in Web Editor NEW
213.0 5.0 56.0 314 KB

An image compress package like Luban for Dart

License: BSD 3-Clause "New" or "Revised" License

Java 1.94% Ruby 11.76% Objective-C 4.01% Dart 82.29%
luban image compression flutter dart

flutter_luban's Introduction

flutter_luban

pub package

An image compress package like Luban for Dart, based on image.This library has no system platform constraints.

Example

   CompressObject compressObject = CompressObject(
         imageFile:imageFile, //image
         path:tempDir.path, //compress to path
         quality: 85,//first compress quality, default 80
         step: 9,//compress quality step, The bigger the fast, Smaller is more accurate, default 6
         mode: CompressMode.LARGE2SMALL,//default AUTO
       );
    Luban.compressImage(compressObject).then((_path) {
        setState(() {
          print(_path);
        });
    });

flutter_luban's People

Contributors

crazecoder avatar inconnu08 avatar leoafarias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flutter_luban's Issues

FileSystemException

Unhandled Exception: Exception: FileSystemException: Cannot open file, path = '/data/user/0/com.example.compress_image_demo/cache/scaled_91926534-c6ab-492c-9318-98d38850098b1214548903574526107.jpg/img_1650868354290.jpg' (OS Error: Not a directory, errno = 20)

Compiler message:

Compiler message:
../../../Desktop/flutter/.pub-cache/hosted/pub.flutter-io.cn/zoomable_image-1.3.1/lib/src/zoomable_image.dart:174:30: Error: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.

  • 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('../../../Desktop/flutter/packages/flutter/lib/src/painting/image_stream.dart').
  • 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('../../../Desktop/flutter/packages/flutter/lib/src/painting/image_stream.dart').
    _imageStream.addListener(_handleImageLoaded);
    ^
    ../../../Desktop/flutter/.pub-cache/hosted/pub.flutter-io.cn/zoomable_image-1.3.1/lib/src/zoomable_image.dart:186:33: Error: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
  • 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('../../../Desktop/flutter/packages/flutter/lib/src/painting/image_stream.dart').
  • 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('../../../Desktop/flutter/packages/flutter/lib/src/painting/image_stream.dart').
    _imageStream.removeListener(_handleImageLoaded);
    ^
    Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
    Failed to build bundle.
    Error launching application on iPhone 11 Pro Max.

Compress multiple files

I have list of files like (sample1.jpg, sample2.jpg, sample3.jpg, ...). I want to compress those files before upload it. I plan to use Dio to upload it. Can you help me the code to do that?

Flutter Web Support ?

This package uses dart:io which is not compatible with flutter web. Can you add web support to this lib? Without dart:io.

Add flutter web support.

Hello,
I am wondering if we could support flutter web.

This could be done by make the input and output images data type uint8list.
Meaning add field Uint8list dataBytes to CompressObject() function and Luban.compressImage() return Uint8list.

Thanks

一直卡在压缩这,代码如下

`final newCompressedPicpath = join((await getTemporaryDirectory()).path, '${DateTime.now().millisecondsSinceEpoch}.png');

CompressObject compressObject = CompressObject(
  imageFile: File(picturePath),
  path: newCompressedPicpath,
  quality: 80,
  step: 9,
  mode: CompressMode.AUTO
);
var path =await (Luban.compressImage(compressObject));`

压缩速度太慢了

image 处理图片的速度一直很慢,作者有计划换其他的实现吗?

现在处理一张1080x1920的图片大概要3秒多。

不过压缩效果极好!

压缩报错

CompressObject compressObject = CompressObject(
imageFile: File('/storage/emulated/0/fluttera/349.jpg'),
path: '/storage/emulated/0/fluttera/15882605447.jpg',
quality: 80,
step: 9,
mode: CompressMode.AUTO
);
var path =await (Luban.compressImage(compressObject));

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Exception: FileSystemException: Cannot open file, path = '/storage/emulated/0/fluttera/15882605447.jpg/img_1588261036457.jpg' (OS Error: No such file or directory, errno = 2)

用的最新版的flutter 和Dart ,图片是本地已经存在的,不知道为什么会提示找不到 报错

压缩时间比较长 需要十几秒

不知道是不是我的代码有问题, 图片是 1920*1080的屏幕截图
Future getImage() async { await ImagePicker.pickImage(source: ImageSource.gallery).then((file) async { CompressObject compressObject = CompressObject( imageFile: file, //image path: file.parent.absolute.path, ); return Luban.compressImage(compressObject); }).then((_path) { setState(() { imgUrlList.clear(); imgUrlList.add(_path); }); }); }

无法打开图片文件

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Exception: FileSystemException: Cannot open file, path = '/data/user/0/com.example.im_flutter/cache/Android.jpg/img_1571561019173.jpg' (OS Error: No such file or directory, errno = 2)

请教关于png压缩成文件,如果进行递归减少文件的size

您好!
请教一下,这段代码是如何通过递归减少文件size的,level这个参数的作用是什么?
谢谢指点
static void _compressPng({ Image image, File file, level: 9, targetSize, }) { var im = encodePng(image, level: level); var tempImageSize = Uint8List.fromList(im).lengthInBytes; if (tempImageSize / 1024 < targetSize) { _small2LargeCompressImage( image: image, file: file, targetSize: targetSize, isJpg: false, ); return; } file.writeAsBytesSync(im); } }

compressImageList: Null check operator used on a null value

Code & error:

    final compressionList = <CompressObject>[];
    for (final image in images) {
      compressionList.add(
        CompressObject(
          imageFile: File(image.path),
          quality: 30,
          step: 9,
        ),
      );
    }

    final compressedImages = <XFile>[];
    await Luban.compressImageList(compressionList).then((paths) {  // <= Exception here
      for (final path in paths) {
        if (path != null) {
          compressedImages.add(XFile(path));
        }
      }
    });
E/flutter (26892): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Null check operator used on a null value
E/flutter (26892): #0      Luban._lubanCompress (package:flutter_luban/src/flutter_luban.dart:91:22)
E/flutter (26892): #1      Luban._lubanCompressList.<anonymous closure> (package:flutter_luban/src/flutter_luban.dart:44:19)
E/flutter (26892): #2      List.forEach (dart:core-patch/growable_array.dart:416:8)
E/flutter (26892): #3      Luban._lubanCompressList (package:flutter_luban/src/flutter_luban.dart:43:13)
E/flutter (26892): #4      _IsolateConfiguration.applyAndTime.<anonymous closure>
package:flutter/…/foundation/_isolates_io.dart:107
E/flutter (26892): #5      Timeline.timeSync (dart:developer/timeline.dart:157:22)
E/flutter (26892): #6      _IsolateConfiguration.applyAndTime
package:flutter/…/foundation/_isolates_io.dart:105
E/flutter (26892): #7      _spawn
package:flutter/…/foundation/_isolates_io.dart:126

List<dynamic> is not a sub-type of type List<String>

static List<String?> _lubanCompressList(List objects) {
var results = [];
objects.forEach((_o) {
results.add(_lubanCompress(_o));
});
return results as List<String?>;
}

The above method was causing that error: Had to change to the below and resolved the error

static List<String?> _lubanCompressList(List objects) {
var results = [];
objects.forEach((_o) {
results.add(_lubanCompress(_o));
});
return (results as List<dynamic?>).cast<String?>();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.