An image compress package like Luban for Dart

Overview

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);
        });
    });

Comments
  • I get this error after upgrading flutter to latest version 1.12.13+hotfix.5

    I get this error after upgrading flutter to latest version 1.12.13+hotfix.5

    Flutter 1.12.13+hotfix.5 • channel stable

    Because every version of flutter_test from sdk depends on image 2.1.4 and flutter_luban 0.1.9+2 depends on image ^2.1.9, flutter_test from sdk is incompatible with flutter_luban 0.1.9+2.

    opened by soile1991 11
  • Compress multiple files

    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?

    opened by saelco 2
  • 无法打开图片文件

    无法打开图片文件

    [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)

    opened by ZhouZhiMin1 2
  • Add flutter web support.

    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

    opened by a7mdragab 1
  • Unable to compress multiple images in a for loop

    Unable to compress multiple images in a for loop

    I am developing a Flutter desktop app for macOS. I have 100 images that I need to compress. If I call the compress function inside a for loop, the whole UI freezes and crashes the app.

    opened by abinmittu 1
  • Compiler message:

    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.
    opened by simanlx 1
  • 请教关于png压缩成文件,如果进行递归减少文件的size

    请教关于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); } }

    opened by guqun 1
  • 压缩时间比较长  需要十几秒

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

    不知道是不是我的代码有问题, 图片是 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); }); }); }

    opened by liuzeze 1
  • Exception on compressImage due to type casting

    Exception on compressImage due to type casting

    By removing type casting I was able to run this correctly.

    Before I was getting the following error. Flutter 2.0.4

    Exception has occurred.
    _CastError (type '(CompressObject) => String?' is not a subtype of type '(dynamic) => FutureOr<String>' in type cast)
    
    opened by leoafarias 0
  • compressImageList: Null check operator used on a null value

    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
    
    opened by Sultanic 0
  • FileSystemException

    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)

    opened by ashishCodixel 0
  • List<dynamic> is not a sub-type of type List<String>

    List is not a sub-type of type List

    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?>(); }

    opened by Okiring 1
  • Added byte data compression

    Added byte data compression

    This is the only package right now that support image compression without needing native code,

    I made fast refactoring to support compression of raw bytes, because on browsers it's impossible to read and write directly on file system

    opened by ahmedNY 0
  • 压缩报错

    压缩报错

    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 ,图片是本地已经存在的,不知道为什么会提示找不到 报错

    opened by 309791679 6
Owner
1/2
1/2
Album Image is based in photo_manager package and has the same concept as image_picker but with a more attractive interface to choose an image or video from the device gallery, whether it is Android or iOS

Album Image is based in photo_manager package and has the same concept as image_picker but with a more attractive interface to choose an image or vide

Phuong Vu 2 Oct 13, 2022
Dart library for decoding/encoding image formats, and image processing.

image Overview A Dart library providing the ability to load, save and manipulate images in a variety of different file formats. The library is written

Brendan Duncan 907 Dec 27, 2022
Flutter simple image crop - A simple and easy to use flutter plugin to crop image on iOS and Android

Image Zoom and Cropping plugin for Flutter A simple and easy used flutter plugin to crop image on iOS and Android. Installation Add simple_image_crop

null 97 Dec 14, 2021
Form builder image picker - Form builder image picker for flutter

form_builder_image_picker Field for picking image(s) from Gallery or Camera for

Ferri Sutanto 0 Jan 28, 2022
Flutter Image add drag sort, Image add drag sort, support click event, delete, add, long press drag sort.

flutter_image_add_drag_sort Flutter Image add drag sort, Image add drag sort, support click event, delete, add, long press drag sort, support video fi

null 5 Jun 23, 2020
Image editing using Paints, Text, Filters, Emoji and Sticker like stories, Built With Flutter

ImageEditorPro Image Editor Plugin with simple, easy support for image editing u

Kaushikkumar Godhani 4 Nov 13, 2022
Imgix package for Dart. Imgix is a CDN service with support for realtime image processing and optimization.

Imgix package for Dart. Imgix is a CDN service with support for realtime image processing and optimization.

Nikkei Inc. 3 Jan 24, 2022
Scouter is a package which was made following the goal to provide a NestJS-like experience to Dart Developers that want to develop Rest APIS

Scouter is a package which was made following the goal to provide a NestJS-like experience to Dart Developers that want to develop Rest APIS Features

Vinicius Amélio 3 Sep 12, 2022
Flutter Package used to 'edit' basics aspects [Brightness, Contrast, Saturation, etc...] from a widget or image.

on_image_matrix on_image_matrix is a Flutter Package used to 'edit' basics aspects [Brightness, Contrast, Saturation, etc...] from a widget or image.

Lucas Josino 6 Oct 23, 2022
A flutter package uses native implementations to resize an image

fast_image_resizer This package uses native implementations to resize an image.

Soeren Schoenbrod 0 Dec 20, 2021
Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.

HtmlWidget monorepo This repo contains the source code for everything HtmlWidget-related. Name Link flutter_widget_from_html_core flutter_widget_from_

Đào Hoàng Sơn 445 Jan 6, 2023
A flutter package to cache network image fastly without native dependencies.

Fast Cached Network Image A flutter package to cache network image fastly without native dependencies, with loader, error builder, and smooth fade tra

CHRISTO 3 Sep 22, 2022
A flutter package that developers have pretty logs instead just printing everything like a newbie

A flutter package that developers have pretty logs instead just printing everything like a newbie. Features Makes it easy to log to console without us

null 2 Nov 28, 2021
Package to select layout per orientation or device size like mobile vs tablet layouts or portrait vs landscape

proxy_layout Package to select layout per orientation or device size like mobile vs tablet layouts or portrait vs landscape Usage You have two widgets

Jimmy Aumard 8 Apr 18, 2021
Flutter package that provide selectable items in list like Column

vertical_picker vertical_picker is flutter package that you can use it as item selector. users with this package be able to select item that is in ver

Sajad Rahimi 6 Nov 19, 2022
A Flutter package of datepicker like Holo Theme in Android

flutter_holo_date_picker A Flutter package of Datepicker inspired by the Holo Theme in Android. Getting Started This plugins displays a Datepicker ins

Kfir Matityahu 48 Nov 28, 2022
Stories like in Instagram, each story can include multiple images and videos. Package supports video, titles, preliminary caching.

flutter_instagram_stories A Flutter package for displaying stories just like Whatsapp & Instagram. Built-in groups (multiple stories with one icon), c

Alex Awaik 125 Dec 9, 2022
Flutter package for displaying grid view of daily task like Github-Contributions.

flutter_annual_task flutter_annual_task Flutter package for displaying grid view of daily task like Github-Contributions. Example Usage Make sure to c

HuanSuh 24 Sep 21, 2022