1 Star 0 Fork 0

hewguo / flutter_native_image

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

flutter_native_image

pub package

Native Flutter Image tools

This plugin aims to have native tools to resize images and reduce their quality by compression. The code is somewhat hacky (especially the iOS part), but it works for my needs and hasn't crashed on me. Feel free to improve it if you want to.

Right now there are a few functions. Please find some examples below.

Usage

Install

Add the following lines to your pubspec.yaml under dependencies

flutter_native_image: ^0.0.6

Compress an image

File compressedFile = await FlutterNativeImage.compressImage(file.path,
    quality: quality, percentage: percentage);

You have to give it a file from the file system and optionally provide a quality (1-100) and a resizing percentage (1-100). Each platform will use it's proper tools to handle the resizing.

To resize the image to the certain size, use following code:

ImageProperties properties = await FlutterNativeImage.getImageProperties(file.path);
File compressedFile = await FlutterNativeImage.compressImage(file.path, quality: 80, 
    targetWidth: 600, targetHeight: 300);

Keep aspect ratio of the file:

ImageProperties properties = await FlutterNativeImage.getImageProperties(file.path);
File compressedFile = await FlutterNativeImage.compressImage(file.path, quality: 80, 
    targetWidth: 600, 
    targetHeight: (properties.height * 600 / properties.width).round());

Get image properties

ImageProperties properties = await FlutterNativeImage.getImageProperties(file.path);

It returns an ImageProperties object containing the width and the height of the image.

Crop an image

File croppedFile = await FlutterNativeImage.cropImage(file.path, originX, originY, width, height);

Returns a file containing the image cropped with the given dimensions.

Contributions

Alexis Leblond (a-leblond) the image properties feature.

Eugene Strokin the resize to target height/width feature

Dae Won Kim null-safety feature

Credits

Shoutouts to Trevor from Vocaro.com. He had the fitting algorithm for resizing images in Objective-C.

Source: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

For preserving exif information, I took the code from googles image_picker github (https://github.com/flutter/plugins/tree/master/packages/image_picker)

空文件

简介

暂无描述 展开 收起
Dart 等 4 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Dart
1
https://gitee.com/hewguo/flutter_native_image.git
git@gitee.com:hewguo/flutter_native_image.git
hewguo
flutter_native_image
flutter_native_image
master

搜索帮助