Skip to main content
Version: 1.x

Taro.getImageInfo(OBJECT)

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

使用方式同 wx.getImageInfo,支持 Promise 化使用。

参数

PropertyTypeDescription
srcstring图片的路径,可以是相对路径、临时文件路径、存储文件路径、网络图片路径
[success]function接口调用成功的回调函数
[fail]function接口调用失败的回调函数
[complete]function接口调用结束的回调函数(调用成功、失败都会执行)

返回值

Promise <object res>

NameTypeDescription
res.widthnumber图片原始宽度,单位px。不考虑旋转。
res.heightnumber图片原始高度,单位px。不考虑旋转。
res.pathstring图片的本地路径
res.orientation'up' / 'up-mirrored' / 'down' / 'down-mirrored' / 'left-mirrored' / 'right' / 'right-mirrored' / 'left'拍照时设备方向(h5平台不支持)
res.typestring图片格式

示例代码

import Taro from '@tarojs/taro'

Taro.getImageInfo(params).then(...)

API支持度

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