Skip to main content
Version: 2.x

Taro.getImageInfo(option)

获取图片信息。网络图片需先配置download域名才能生效。

参考文档

类型

(option: Option) => Promise<SuccessCallbackResult>

参数

Option

参数类型必填说明
srcstring图片的路径,可以是相对路径、临时文件路径、存储文件路径、网络图片路径
complete(res: CallbackResult) => void接口调用结束的回调函数(调用成功、失败都会执行)
fail(res: CallbackResult) => void接口调用失败的回调函数
success(result: SuccessCallbackResult) => void接口调用成功的回调函数

SuccessCallbackResult

参数类型默认值说明
heightnumber图片原始高度,单位px。不考虑旋转。
orientation"up" | "up-mirrored" | "down" | "down-mirrored" | "left-mirrored" | "right" | "right-mirrored" | "left""up"拍照时设备方向
pathstring图片的本地路径
typestring图片格式
widthnumber图片原始宽度,单位px。不考虑旋转。
errMsgstring调用结果

orientation

参数说明
up默认方向(手机横持拍照),对应 Exif 中的 1。或无 orientation 信息。
up-mirrored同 up,但镜像翻转,对应 Exif 中的 2
down旋转180度,对应 Exif 中的 3
down-mirrored同 down,但镜像翻转,对应 Exif 中的 4
left-mirrored同 left,但镜像翻转,对应 Exif 中的 5
right顺时针旋转90度,对应 Exif 中的 6
right-mirrored同 right,但镜像翻转,对应 Exif 中的 7
left逆时针旋转90度,对应 Exif 中的 8

示例代码

Taro.getImageInfo({
src: 'images/a.jpg',
success: function (res) {
console.log(res.width)
console.log(res.height)
}
})
Taro.chooseImage({
success: function (res) {
Taro.getImageInfo({
src: res.tempFilePaths[0],
success: function (res) {
console.log(res.width)
console.log(res.height)
}
})
}
})

API 支持度

API微信小程序百度小程序支付宝小程序H5React Native
Taro.getImageInfo✔️✔️✔️✔️✔️