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

image_cropping 封面
插件详情v0.0.16

image_cropping

此包可帮助您按比例和自由缩放裁剪图像。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
340
喜欢数
93
Pub 分数
135

安装插件

flutter pub add image_cropping

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

image_cropping 包使 Flutter 开发者能够实现图像裁剪功能,支持自定义纵横比和自由缩放。它支持对裁剪区域进行精确控制,非常适合用于头像、缩略图或任何需要图像调整大小和修剪的场景。该包兼容多个平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,确保在各种环境中行为一致。通过简单直观的 API,它可以无缝集成到现有应用中,提升用户体验。

适合场景

  • 个人资料图片裁剪
  • 缩略图生成
  • 图像编辑工具
  • 用户头像自定义
  • 内容创作工作流程
  • 社交媒体图像处理

主要特点

  • 纵横比锁定
  • 自由缩放裁剪
  • 跨平台兼容性
  • 简单集成API
  • 实时预览支持
  • 对多个平台的支持

适合对象

  • 移动应用开发者
  • Web应用程序创建者
  • 图像编辑功能实现者
  • 社交媒体平台
  • 电子商务应用
  • 面向用户的照片上传系统

使用建议

  • 需要图像输入验证
  • 可能需要额外的UI组件以实现完整的用户体验
  • 大图像的性能影响
  • 仅限基本裁剪操作
  • 无内置图像滤镜
  • 依赖外部依赖项以实现高级功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

image_cropping

image_cropping version MIT License MIT License

This plugin supports cropping and rotating images for multiplatform. It Allow inclusion of background, Rotation of image, changing ratio of selection as per requirements.

Allow inclusion of background.

Image Plugin

Rotation of image.

Image Plugin

Change ratio of selection.

Image Plugin

Installation

If you are targeting web, don't forget to add worker.js in your project's root directory.

You can also add worker.js.deps and worker.js.map but they are optional and only used for development.

These 3 files are generated when running the following command in the example folder:

dart compile js -O1 -o web/worker.js lib/worker.dart

For more details on the command, check this link. It converts the dart code to JS, which will then be run in a web worker.

Example
final croppedBytes = await ImageCropping.cropImage(
    context: context,
    imageBytes: bytes,
    onImageStartLoading: () {
        showLoader();
    },
    onImageEndLoading: () {
        hideLoader();
    },
    onImageDoneListener: (data) {
        // You can also use a listener instead of awaiting the function
        setState(() {
          imageBytes = data;
        });
    },
    selectedImageRatio: ImageRatio.RATIO_1_1,
    visibleOtherAspectRatios: true,
    squareBorderWidth: 2,
    squareCircleColor: Colors.black,
    defaultTextColor: Colors.orange,
    selectedTextColor: Colors.black,
    colorForWhiteSpace: Colors.grey,
    encodingQuality: 80,
    outputImageFormat: OutputImageFormat.jpg, 
    workerPath: 'crop_worker.js',
);
Required parameters
BuildContext:

Context is use to push new screen for image cropping.

_imageBytes:

Image bytes is use to draw image in device and if image not fits in device screen then we manage background color(if you have passed colorForWhiteSpace or else White background) in image cropping screen.

_onImageStartLoading:

This is a callback. you have to override and show dialog or etc when image cropping is in loading state.

_onImageEndLoading:

This is a callback. you have to override and hide dialog or etc when image cropping is ready to show result in cropping screen.

_onImageDoneListener:

This is a callback. you have to override and you will get Uint8List as result.

Optional parameters

ImageRatio:

This property contains ImageRatio value. You can set the initialized aspect ratio when starting the cropper by passing a value of ImageRatio. default value is ImageRatio.FREE

visibleOtherAspectRatios:

This property contains boolean value. If this properties is true then it shows all other aspect ratios in cropping screen. default value is true.

squareBorderWidth:

This property contains double value. You can change square border width by passing this value.

squareCircleColor:

This property contains Color value. You can change square circle color by passing this value.

defaultTextColor:

This property contains Color value. By passing this property you can set aspect ratios color which are unselected.

selectedTextColor:

This property contains Color value. By passing this property you can set aspect ratios color which is selected.

colorForWhiteSpace:

This property contains Color value. By passing this property you can set background color, if screen contains blank space.

encodingQuality

Set the encodingQuality of the cropped image. Defaults to 100 (max). High quality involves bigger image file size.

outputImageFormat

Output format of cropped image, can be PNG or JPG, default is JPG.

workerPath

You may want to change the worker.js name, especially if you use other web workers and you already have a worker.js file. Defaults to 'worker.js'.

Note:

For flutter web, copy worker.js from example folder to the project, else it will not work. The result returns in Uint8List. so it can be lost later, you are responsible for storing it somewhere permanent (if needed).

Guideline for contributors

Contribution towards our repository is always welcome, we request contributors to create a pull request to the develop branch only.

Guideline to report an issue/feature request

It would be great for us if the reporter can share the below things to understand the root cause of the issue.

  • Library version
  • Code snippet
  • Logs if applicable
  • Device specification like (Manufacturer, OS version, etc)
  • Screenshot/video with steps to reproduce the issue

Library used

LICENSE!

Image Cropper is MIT-licensed.

Let us know!

We’d be really happy if you send us links to your projects where you use our component. Just send an email to sales@mindinventory.com And do let us know if you have any questions or suggestion regarding our work.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目