title: Taro.getImageInfo(option)

sidebar_label: getImageInfo

Obtains image information. For network images, it only takes effect when the download domain name is configured.

Reference

Type

  1. (option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

Property Type Required Description
src string Yes The path to the image. It can be a relative path, a temporary file path, a file storage path, or a path to a network image.
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

SuccessCallbackResult

Property Type Default Description
height number The original height of the image (in px). Rotation is not considered.
width number The original width of the image (in px). Rotation is not considered.
orientation "up" | "up-mirrored" | "down" | "down-mirrored" | "left-mirrored" | "right" | "right-mirrored" | "left" "up" Device orientation when taking photos
path string The local path to the image
type string Image format
errMsg string Call result

orientation

Property Description
up Default orientation (landscape). It is 1 in Exif. Or it indicates no orientation information.
up-mirrored Mirrored orientation of up. It is 2 in Exif.
down Rotates the device 180 degrees. It is 3 in Exif.
down-mirrored Mirrored orientation of down. It is 4 in Exif.
left-mirrored Mirrored orientation of left. It is 5 in Exif.
right Rotates the device 90 degrees clockwise. It is 6 in Exif.
right-mirrored Mirrored orientation of right. It is 7 in Exif.
left Rotates the device 90 degrees counterclockwise. It is 8 in Exif.

Sample Code

  1. Taro.getImageInfo({
  2. src: 'images/a.jpg',
  3. success: function (res) {
  4. console.log(res.width)
  5. console.log(res.height)
  6. }
  7. })
  8. Taro.chooseImage({
  9. success: function (res) {
  10. Taro.getImageInfo({
  11. src: res.tempFilePaths[0],
  12. success: function (res) {
  13. console.log(res.width)
  14. console.log(res.height)
  15. }
  16. })
  17. }
  18. })

API Support

API WeChat Mini-Program Baidu Smart-Program Alipay Mini-Program H5 React Native
Taro.getImageInfo ✔️ ✔️ ✔️ ✔️ ✔️