Skip to main content
Version: 3.x

Taro.getImageInfo(option)

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

Reference

Type

(option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
srcstringYesThe 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) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

SuccessCallbackResult

PropertyTypeDefaultDescription
heightnumberThe original height of the image (in px). Rotation is not considered.
widthnumberThe 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
pathstringThe local path to the image
typestringImage format
errMsgstringCall result

orientation

PropertyDescription
upDefault orientation (landscape). It is 1 in Exif. Or it indicates no orientation information.
up-mirroredMirrored orientation of up. It is 2 in Exif.
downRotates the device 180 degrees. It is 3 in Exif.
down-mirroredMirrored orientation of down. It is 4 in Exif.
left-mirroredMirrored orientation of left. It is 5 in Exif.
rightRotates the device 90 degrees clockwise. It is 6 in Exif.
right-mirroredMirrored orientation of right. It is 7 in Exif.
leftRotates the device 90 degrees counterclockwise. It is 8 in Exif.

Sample Code

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 Support

APIWeChat Mini-ProgramBaidu Smart-ProgramAlipay Mini-ProgramH5React Native
Taro.getImageInfo✔️✔️✔️✔️✔️