更新记录
0.0.1(2026-05-07)
- 初始版本
- 支持裁剪、旋转、翻转、缩放、模糊
- 支持扩展填充、边缘模糊、渐进式模糊
- 支持圆角、圆形裁剪
- 支持图片合成、压缩、水印
- 支持获取 EXIF 信息
平台兼容性
uni-app(4.87)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | √ | √ | √ | √ |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(5.0)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | √ |
lime-image-processor 图片处理 API
跨平台图片处理工具,基于 UTS 实现,支持多种图片处理操作。
核心价值
- 一站式解决方案:从基础裁剪到高级视觉效果,一套 API 搞定所有图片处理需求
- 跨平台兼容:一次编码,多端运行(Android、iOS、Harmony、Web、微信小程序)
- 高性能实现:基于 Canvas 2D API,采用可分离卷积算法实现高效模糊处理
- 智能组合:操作之间智能关联,如
extendFill与edgeBlur自动配合
主要功能
🎨 基础处理
- 裁剪 (crop):精确提取图片区域
- 旋转 (rotate):任意角度旋转,自动计算画布尺寸
- 翻转 (flip):水平/垂直翻转
- 缩放 (scale):按比例缩放
✨ 模糊效果
- 高斯模糊 (blur):全图均匀模糊
- 边缘模糊 (edgeBlur):渐变边缘模糊,音乐播放器背景特效
- 渐进式模糊 (progressiveBlur):单向渐变模糊
🔧 形状处理
- 圆角 (roundCorner):添加圆角效果
- 圆形裁剪 (circleClip):生成圆形头像
📐 智能扩展
- 扩展填充 (extendFill):智能扩展画布,保持原图位置
🎯 高级合成
- 图片合成 (composite):多图叠加
- 水印 (watermark):文字/图片水印,支持平铺模式
📊 信息获取
- EXIF 信息 (getImageExif):获取图片元数据
安装方法
- 在 uni-app 插件市场中搜索并导入
lime-image-processor - 导入后在页面引入相关方法
- 需要自定义基座才能使用(Android/iOS)
自定义基座准备(Android/iOS)
重要:在 Android 和 iOS 平台上使用本插件时,需要特别注意以下事项
自定义基座前的准备工作:
- 必须先在页面中引入相关函数:在生成自定义基座之前,确保至少在一个页面中引入并使用插件的相关函数
- 避免被树摇掉:如果没有在代码中实际引用插件函数,构建工具可能会将其视为未使用的代码而在构建过程中"树摇"掉,导致自定义基座中缺少必要的插件功能
示例:
// 在页面中至少添加以下引用代码
import { processImage } from '@/uni_modules/lime-image-processor'
快速开始
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/image.jpg',
operations: [
{ type: 'crop', x: 0, y: 0, width: 100, height: 100 }
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
操作示例
crop - 裁剪
从原图中裁剪出指定区域。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/image.jpg',
operations: [
{
type: 'crop',
x: 100,
y: 100,
width: 300,
height: 300
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'crop' |
是 | 操作类型:裁剪 |
| x | number |
是 | 裁剪区域左上角 x 坐标 |
| y | number |
是 | 裁剪区域左上角 y 坐标 |
| width | number |
是 | 裁剪区域宽度 |
| height | number |
是 | 裁剪区域高度 |
rotate - 旋转
按指定角度旋转图片。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/image.jpg',
operations: [
{
type: 'rotate',
degree: 90
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'rotate' |
是 | 操作类型:旋转 |
| degree | number |
是 | 旋转角度(度),正值顺时针,负值逆时针 |
flip - 翻转
水平或垂直翻转图片。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/image.jpg',
operations: [
{
type: 'flip',
horizontal: true,
vertical: false
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'flip' |
是 | 操作类型:翻转 |
| horizontal | boolean |
否 | 是否水平翻转,默认 false |
| vertical | boolean |
否 | 是否垂直翻转,默认 false |
scale - 缩放
按比例缩放图片。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/image.jpg',
operations: [
{
type: 'scale',
scaleX: 0.5,
scaleY: 0.5
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'scale' |
是 | 操作类型:缩放 |
| scaleX | number |
是 | X 方向缩放比例 |
| scaleY | number |
是 | Y 方向缩放比例 |
blur - 模糊
高斯模糊效果,整个图片均匀模糊。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/image.jpg',
operations: [
{
type: 'blur',
radius: 20
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'blur' |
是 | 操作类型:模糊 |
| radius | number |
是 | 模糊半径(像素),值越大越模糊 |
平台说明:鸿蒙平台的模糊效果受限于系统 API,边缘模糊和渐进式模糊的效果可能不如其他平台平滑。
roundCorner - 圆角
给图片添加圆角效果。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/photo.jpg',
operations: [
{
type: 'roundCorner',
radius: 50
}
],
format: 'png',
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'roundCorner' |
是 | 操作类型:圆角 |
| radius | number |
是 | 圆角半径(像素) |
注意:建议使用 PNG 格式输出以保留透明背景
circleClip - 圆形裁剪
将图片裁剪为圆形(头像效果)。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/avatar.jpg',
operations: [
{
type: 'circleClip'
}
],
format: 'png',
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'circleClip' |
是 | 操作类型:圆形裁剪 |
注意:建议使用 PNG 格式输出以保留透明背景
extendFill - 扩展填充
将图片扩展到目标尺寸,常用于生成背景图。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/photo.jpg',
operations: [
{
type: 'extendFill',
targetWidth: 800,
targetHeight: 1200,
direction: 'vertical',
position: 50
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'extendFill' |
是 | 操作类型:扩展填充 |
| targetWidth | number |
是 | 目标宽度(像素) |
| targetHeight | number |
是 | 目标高度(像素) |
| direction | 'vertical' \| 'horizontal' |
否 | 扩展方向,默认 'vertical' |
| position | number \| string |
否 | 原图位置,像素值(50)或百分比('50%'),默认居中 |
edgeBlur - 边缘模糊
核心功能:为图片边缘添加渐变模糊效果,常用于生成音乐播放器背景、全屏海报等场景。
设计原理:
- 将图片分为三个区域:顶部模糊区、中间清晰区、底部模糊区
- 通过渐变蒙版控制模糊强度,实现平滑过渡
- 支持自动提取图片主色并叠加,增强视觉层次感
典型应用场景:
- 🎵 音乐播放器背景:中间显示专辑封面,上下边缘渐变模糊
- 🖼️ 全屏海报:主图居中清晰,边缘自然过渡
- 📱 移动端卡片:内容区域清晰,边缘柔和模糊
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
// 基础用法:垂直边缘模糊
processImage({
src: '/static/photo.jpg',
operations: [
{
type: 'edgeBlur',
radius: 30,
direction: 'vertical',
regions: [0.2, 0.6, 0.2], // [顶部模糊区, 中间清晰区, 底部模糊区]
transition: 0.2, // 过渡区域大小
enableColorOverlay: true, // 启用主色叠加
overlayOpacity: 0.4 // 叠加层透明度
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'edgeBlur' |
是 | 操作类型:边缘模糊 |
| radius | number |
是 | 模糊强度(像素),值越大越模糊 |
| direction | 'vertical' \| 'horizontal' |
是 | 模糊方向:垂直方向(上下)或水平方向(左右) |
| regions | [number, number, number] |
否 | 区域比例 [模糊区比例, 清晰区比例, 模糊区比例],默认 [0.2, 0.6, 0.2] |
| transition | number |
否 | 过渡区域大小(0-1),默认 0.1,值越大过渡越平滑 |
| enableColorOverlay | boolean |
否 | 是否启用主色叠加,默认 false。启用后会自动提取图片边缘区域的主色调进行叠加 |
| overlayOpacity | number |
否 | 叠加层不透明度(0-1),默认 0.4 |
| overlayColors | [[number,number,number,number], [number,number,number,number]] |
否 | 自定义叠加颜色数组,格式为 [[R,G,B,alpha], [R,G,B,alpha]],分别对应上下(或左右)边缘颜色 |
与 extendFill 组合使用(推荐):
当 edgeBlur 紧跟在 extendFill 操作之后时,会自动计算模糊区域,无需手动设置 regions 参数:
processImage({
src: '/static/album.jpg',
operations: [
{
type: 'extendFill',
targetWidth: 400,
targetHeight: 800,
direction: 'vertical',
position: '50%' // 原图居中
},
{
type: 'edgeBlur',
radius: 40,
direction: 'vertical',
transition: 0.2,
enableColorOverlay: true,
overlayOpacity: 0.4
}
],
success: (res) => {
// 生成的图片:中间保持原图清晰,上下扩展区域模糊并叠加主色
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
工作原理:
extendFill会记录原图在扩展后画布中的位置信息,edgeBlur读取这些信息后,会自动将清晰区设置为原图区域,模糊区设置为扩展填充的区域,实现完美的渐变过渡效果。平台说明:鸿蒙平台的边缘模糊效果受限于系统 API,效果可能不如其他平台平滑
progressiveBlur - 渐进式模糊
从边缘向内渐变的模糊效果。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/photo.jpg',
operations: [
{
type: 'progressiveBlur',
direction: 'down',
radius: 10,
offset: 0.3,
interpolation: 0.4
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'progressiveBlur' |
是 | 操作类型:渐进式模糊 |
| direction | 'down' \| 'up' \| 'right' \| 'left' |
是 | 模糊方向 |
| radius | number |
是 | 最大模糊半径(像素) |
| offset | number |
是 | 开始模糊的位置(0-1.0) |
| interpolation | number |
是 | 过渡范围(0-1.0) |
平台说明:鸿蒙平台的渐进式模糊效果受限于系统 API,效果可能不如其他平台平滑
链式操作示例
多个操作可以组合使用,按顺序执行。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/photo.jpg',
operations: [
{ type: 'scale', scaleX: 0.8, scaleY: 0.8 },
{ type: 'rotate', degree: 15 },
{ type: 'roundCorner', radius: 30 },
{ type: 'blur', radius: 5 }
],
quality: 0.9,
format: 'jpg',
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
扩展填充 + 边缘模糊组合
智能组合使用,自动计算模糊区域。
示例代码:
import { processImage, type ProcessImageOptions } from '@/uni_modules/lime-image-processor'
processImage({
src: '/static/photo.jpg',
operations: [
{
type: 'extendFill',
targetWidth: 800,
targetHeight: 1200,
direction: 'vertical',
position: 50
},
{
type: 'edgeBlur',
radius: 40,
direction: 'vertical',
transition: 0.2,
enableColorOverlay: true,
overlayOpacity: 0.4
}
],
success: (res) => {
console.log(res.tempFilePath)
}
} as ProcessImageOptions)
提示:与 extendFill 组合使用时,edgeBlur 的 regions 参数可以省略,会自动根据原图位置计算
其他 API
composite - 图片合成
将多张图片叠加到底图上。
示例代码:
import { composite, type CompositeOptions } from '@/uni_modules/lime-image-processor'
composite({
src: '/static/bg.jpg',
images: [
{ src: '/static/logo.png', position: 'topLeft', alpha: 0.8 },
{ src: '/static/avatar.png', position: { x: 100, y: 100 }, alpha: 1 }
],
success: (res) => {
console.log(res.tempFilePath)
}
} as CompositeOptions)
watermark - 添加水印
添加水印,支持文字水印和图片水印。
示例代码:
import { watermark, type WatermarkOptions } from '@/uni_modules/lime-image-processor'
watermark({
src: '/static/photo.jpg',
texts: [{
text: 'WATERMARK',
tile: true,
tileGap: { x: 50, y: 50 },
rotate: -30,
fontSize: 24,
color: '#ff0000',
alpha: 0.4
}],
format: 'png',
success: (res) => {
console.log(res.tempFilePath)
}
} as WatermarkOptions)
getImageExif - 获取 EXIF 信息
获取图片的 EXIF 元数据信息。
示例代码:
import { getImageExif, type GetImageExifOptions } from '@/uni_modules/lime-image-processor'
getImageExif({
src: '/static/photo.jpg',
success: (res) => {
console.log('相机品牌', res.make)
console.log('相机型号', res.model)
console.log('拍摄时间', res.dateTime)
console.log('GPS信息', res.gps)
}
} as GetImageExifOptions)
详细 API 文档
processImage
图片处理主 API,支持多种操作链式执行。
提示词示例:
请使用 lime-image-processor 插件将图片缩放到 50%,然后添加 20px 的圆角,最后输出为 PNG 格式。
ProcessImageOptions 参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| src | string |
是 | 图片源路径(本地路径或网络 URL) |
| operations | ImageOperation[] |
是 | 操作数组,按顺序执行 |
| quality | number |
否 | 输出质量 0.0-1.0,默认 0.9 |
| format | 'jpg' \| 'png' \| 'webp' |
否 | 输出格式,默认 'jpg' |
| success | Function |
否 | 成功回调 |
| fail | Function |
否 | 失败回调 |
返回说明 (ImageProcessResult)
| 属性 | 类型 | 说明 |
|---|---|---|
| tempFilePath | string |
临时文件路径(可能是 dataURL 或真实文件路径) |
| width | number |
图片宽度(像素) |
| height | number |
图片高度(像素) |
| size | number |
文件大小(字节) |
composite
图片合成,将多张图片叠加到底图上。
CompositeOptions 参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| src | string |
是 | 底图路径 |
| images | array |
是 | 要合成的图片数组 |
| images[].src | string |
是 | 合成图片路径 |
| images[].position | string \| object |
是 | 位置,预设如 'topLeft'、'center'、'bottomRight',或自定义坐标 {x, y} |
| images[].alpha | number |
否 | 透明度 0.0-1.0,默认 1 |
| quality | number |
否 | 输出质量,默认 0.9 |
| format | string |
否 | 输出格式,默认 'jpg' |
| success | Function |
否 | 成功回调 |
| fail | Function |
否 | 失败回调 |
watermark
添加水印,支持文字水印和图片水印。
WatermarkOptions 参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| src | string |
否 | 源图片路径,不提供则只生成带水印的画布 |
| width | number |
否 | 画布宽度(与 src 二选一) |
| height | number |
否 | 画布高度(与 src 二选一) |
| background | string |
否 | 背景颜色(无 src 时使用) |
| texts | array |
否 | 文字水印数组 |
| images | array |
否 | 图片水印数组 |
| format | string |
否 | 输出格式,默认 'png' |
| success | Function |
否 | 成功回调 |
| fail | Function |
否 | 失败回调 |
文字水印参数 (TextWatermark)
| 参数 | 类型 | 说明 |
|---|---|---|
| text | string |
水印文字内容 |
| tile | boolean |
是否平铺显示,默认 false |
| tileGap | object |
平铺间距 {x, y}(像素) |
| rotate | number |
旋转角度(度) |
| fontSize | number |
字体大小 |
| color | string |
文字颜色(十六进制) |
| alpha | number |
透明度 0.0-1.0 |
图片水印参数 (ImageWatermark)
| 参数 | 类型 | 说明 |
|---|---|---|
| src | string |
水印图片路径 |
| position | string \| object |
位置 |
| alpha | number |
透明度 0.0-1.0 |
| rotate | number |
旋转角度(度) |
getImageExif
获取图片的 EXIF 元数据信息。
GetImageExifOptions 参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| src | string |
是 | 图片源路径 |
| success | Function |
否 | 成功回调 |
| fail | Function |
否 | 失败回调 |
返回说明 (ExifInfo)
| 属性 | 类型 | 说明 |
|---|---|---|
| make | string |
相机品牌 |
| model | string |
相机型号 |
| dateTime | string |
拍摄时间 |
| gps | object |
GPS 信息 {latitude, longitude} |
| ... | object |
其他 EXIF 字段 |
位置预设值
图片位置支持以下预设值:
| 预设值 | 说明 |
|---|---|
'topLeft' |
左上角 |
'topCenter' |
顶部居中 |
'topRight' |
右上角 |
'centerLeft' |
左侧居中 |
'center' |
正中间 |
'centerRight' |
右侧居中 |
'bottomLeft' |
左下角 |
'bottomCenter' |
底部居中 |
'bottomRight' |
右下角 |
或使用自定义坐标:
{ x: 50, y: 50 } // 距离左上角 50px
{ left: 10, bottom: 20 } // 距离左侧 10px,底部 20px
错误码
| 错误码 | 说明 |
|---|---|
| 9010001 | 图片加载失败 |
| 9010002 | 图片格式不支持 |
| 9010003 | 裁剪区域超出范围 |
| 9010004 | 保存失败 |
| 9010005 | 参数无效 |
| 9010007 | 合成失败 |
| 9010008 | 水印失败 |
| 9010009 | 获取 EXIF 信息失败 |
注意事项
- 所有操作按顺序执行,前一个操作的输出作为后一个操作的输入
- tempFilePath 可能是 dataURL 也可能是真实文件路径,取决于平台
- 边缘模糊配合扩展填充使用时,可省略 regions 参数,会自动计算
- 圆角和圆形裁剪建议使用 PNG 格式以保留透明背景
- 水印支持平铺模式,适合批量制作水印图
- 鸿蒙平台的
edgeBlur(边缘模糊)和progressiveBlur(渐进式模糊)效果受限于系统 API,效果可能不如其他平台平滑
平台支持
| 平台 | 支持情况 |
|---|---|
| Android | ✅ 完全支持 |
| iOS | ✅ 完全支持 |
| Harmony | ✅ 完全支持 |
| Web | ✅ 完全支持 |

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 71331
赞赏 566
下载 11809132
赞赏 1911
赞赏
京公网安备:11010802035340号