This API is used via wx.chooseImage(Object object).
Attribute | Type | Valid Values and Descriptions | Default value | Required | Description |
count | number | - | 9 | No | Maximum selectable number of images |
sizeType | Array.<string> | Original: Original image Compressed: Compressed image | ['original', 'compressed'] | No | Dimensions of the Selected Image |
sourceType | Array.<string> | Album: Select image from album Camera: Uses the camera | ['album', 'camera'] | No | Select image source |
success | function | - | - | No | Callback Function of Successful Interface Call |
fail | function | - | - | No | Callback Function of Failing Interface Call |
complete | function | - | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
tempFilePaths | Array.<string> | List of local temporary file paths for the image (Local Path) |
tempFiles | Array.<string> | List of local temporary files for the image |
Attribute | Type | Description |
path | string | Local temporary file path |
size | number | Size of local temporary files, measured in bytes. |
wx.chooseImage({count: 1,sizeType: ['original', 'compressed'],sourceType: ['album', 'camera'],success(res) {// tempFilePath can be used as the src attribute in an img tag to display the imageconst tempFilePaths = res.tempFilePaths}})
This API is used via wx.compressImage(Object object).
Attribute | Type | Default value | Required | Description |
src | string | - | Yes | Image path, the path of the image, supporting local paths and code package paths. |
quality | number | 80 | No | Compression quality, ranging from 0 to 100. The lower the value, the lower the quality and the higher the compression rate (only effective for jpg). |
compressedWidth | number | - | No | The width of the compressed image, in pixels (px). If not specified, it will default to proportional scaling based on compressedHeight. |
compressedHeight | number | - | No | The height of the compressed image, in pixels (px). If not specified, it will default to proportional scaling based on compressedWidth. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
tempFilePath | string | The temporary file path of the compressed image (local path). |
wx.compressImage({src: '', // Image pathquality: 80 // Compression quality})
This API is used via wx.getImageInfo(Object object).
Attribute | Type | Default value | Required | Description |
src | string | - | Yes | The path of the image, which can be a relative path, temporary file path, storage file path, or network image path. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
width | number | Original width of the image, in pixels (px). Rotation is not considered. |
height | number | Original height of the image, in pixels (px). Rotation is not considered. |
path | string | Local path of image |
orientation | string | |
type | string | Image format |
Value | Description |
up | Default orientation (photographing horizontally with a mobile phone), corresponding to 1 in Exif, or without orientation information. |
up-mirrored | Identical to 'up', but mirrored, corresponding to 2 in Exif. |
down | Rotating 180 degrees, corresponding to 3 in Exif. |
down-mirrored | Identical to 'down', but mirrored, corresponding to 4 in Exif. |
left-mirrored | Identical to 'left', but mirrored, corresponding to 5 in Exif. |
right | Rotating 90 degrees clockwise, corresponding to 6 in Exif. |
right-mirrored | Identical to 'right', but mirrored, corresponding to 7 in Exif. |
left | Rotating 90 degrees counterclockwise, corresponding to 8 in Exif. |
Legal value | Description |
unknown | unknown format |
jpeg | jpeg compression format |
png | png compression format |
gif | gif compression format |
tiff | tiff compression format |
wx.getImageInfo({src: 'images/a.jpg',success(res) {console.log(res.width)console.log(res.height)},})wx.chooseImage({success(res) {wx.getImageInfo({src: res.tempFilePaths[0],success(res) {console.log(res.width)console.log(res.height)},})},})
This API is used via wx.previewImage(Object object).
Attribute | Type | Default value | Required | Description |
urls | Array.<string> | - | Yes | List of image links to be previewed. Cloud file ID is supported. |
current | string | The first one in urls. | No | The link to the currently displayed image. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.previewImage({current: '', // The HTTP link to the currently displayed image.urls: [], // List of HTTP image links to be previewed.})
This API is used via wx.previewMedia(Object object).
Attribute | Type | Default value | Required | Description |
sources | Array.<Object> | | Yes | List of resources to preview |
current | number | 0 | No | Serial number of the currently displayed resource |
filePath | string | - | Yes | Image file path, can be temporary file path or permanent file path (local path), does not support network image paths |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
This API is used via wx.saveImageToPhotosAlbum(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | Image file path, can be temporary file path or permanent file path (local path), does not support network image paths |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.saveImageToPhotosAlbum({success(res) {},})
Was this page helpful?