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
(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
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
API |
WeChat Mini-Program |
Baidu Smart-Program |
Alipay Mini-Program |
H5 |
React Native |
Taro.getImageInfo |
✔️ |
✔️ |
✔️ |
✔️ |
✔️ |