title: Taro.getImageInfo(OBJECT)

sidebar_label: getImageInfo

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

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

参数

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

返回值

Promise <object res>

Name Type Description
res.width number 图片原始宽度,单位px。不考虑旋转。
res.height number 图片原始高度,单位px。不考虑旋转。
res.path string 图片的本地路径
res.orientation 'up' / 'up-mirrored' / 'down' / 'down-mirrored' / 'left-mirrored' / 'right' / 'right-mirrored' / 'left' 拍照时设备方向(h5平台不支持)
res.type string 图片格式

示例代码

  1. import Taro from '@tarojs/taro'
  2. Taro.getImageInfo(params).then(...)

API支持度

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