更新记录

1.0.0(2026-08-12) 下载此版本

  • 首次发布:提供图片裁剪、旋转、翻转、滤镜、涂鸦、文字、马赛克、历史记录与导出能力。
  • 支持App-Vue 与 H5,且不依赖第三方组件。

平台兼容性

AI 图片编辑器

组件名:ai-image-editor

零依赖的 Vue 2 uni-app 图片编辑组件,基于原生 Canvas 实现图片裁剪、旋转、翻转、滤镜、涂鸦、文字、马赛克、撤销/重做与图片导出。

安装

从插件市场导入后,保留项目中的 uni_modules/ai-image-editor 目录。项目已开启 easycom 时可直接使用组件;否则在页面中手动导入:

import AiImageEditor from '@/uni_modules/ai-image-editor/components/ai-image-editor/ai-image-editor.vue'

export default {
  components: { AiImageEditor }
}

基础使用

<template>
  <view>
    <ai-image-editor
      ref="editor"
      :src="imagePath"
      :width="canvasWidth"
      :height="420"
      :show-toolbar="true"
      :show-actions="true"
      @load="handleLoad"
      @export="handleExport"
    />
    <button @click="exportImage">获取编辑结果</button>
  </view>
</template>

<script>
export default {
  data() {
    return { imagePath: '', canvasWidth: 375 }
  },
  onLoad() {
    this.canvasWidth = uni.getSystemInfoSync().windowWidth
    this.imagePath = '/static/demo.jpg'
  },
  methods: {
    handleLoad(size) {
      console.log('图片尺寸:', size.width, size.height)
    },
    async exportImage() {
      const result = await this.$refs.editor.getImageData({ fileType: 'png', quality: 0.92 })
      console.log(result.tempFilePath)
    },
    handleExport(result) {
      console.log(result.tempFilePath)
    }
  }
}
</script>

属性

属性 类型 默认值 说明
src String '' 本地或合法远程图片地址
width Number 屏幕宽度 Canvas 宽度,单位 px
height Number 400 Canvas 高度,单位 px
canvasId String 自动生成 Canvas 标识;多实例时无需传入,也可自行指定
showToolbar Boolean false 显示内置工具栏
showActions Boolean false 显示撤销、重做与导出操作栏
tools Array 全部工具 内置工具栏可显示的工具:croprotatefilterdrawtextmosaic

事件

事件 参数 说明
load { width, height } 图片加载成功
error 错误对象 图片加载失败
change { hasChanges } 编辑状态变化
toolChange / modeChange 工具名或空字符串 当前工具变化
export { tempFilePath, width, height } 点击内置导出按钮成功
save { success, error? } 保存相册结果

方法

通过 ref 调用:

方法 说明
loadImage(src) 加载新图片,返回图片尺寸 Promise
getImageData(options) 导出图片,返回{ tempFilePath, width, height } Promise
exportImg() 触发内置导出事件
saveToAlbum(options) 保存到系统相册,返回 Promise
enterCropMode() / confirmCrop() / cancelCrop() 控制裁剪流程
enterMosaicMode() / selectMosaicSize(size) 控制马赛克流程
rotate90() 顺时针旋转 90 度
undo() / redo() / reset() 历史操作与还原
finishTool() 退出当前工具

options 支持 fileTypepngjpg)与 quality(0 到 1)。

平台说明

  • 已声明支持:微信小程序、App-Vue、H5、Vue 2;微信小程序请使用 1.0.1 或更高版本。
  • H5 使用远程图片时,图片服务器必须配置 CORS;否则浏览器安全策略会限制 Canvas 导出。
  • 微信小程序使用远程图片时,需在小程序后台配置下载域名。
  • 微信小程序的 Canvas 为原生组件,组件已使用 cover-view 承载裁剪与文字覆盖层;请勿将组件放入 scroll-viewswiperpicker-viewmovable-view
  • 调用 saveToAlbum 时,App 或小程序可能要求用户授权相册权限。
  • 本组件不支持 nvue 和 Vue 3。

发布前检查

发布者请在插件市场后台补充真实的仓库地址、联系方式、预览图与演示地址;如变更平台支持范围,也请同步更新 package.json 的兼容性声明。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT License

Copyright (c) 2026

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

暂无用户评论。