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. | Original: Original image Compressed: Compressed image | ['original', 'compressed'] | No | Dimensions of the Selected Image |
sourceType | Array. | 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. | List of local temporary file paths for the image (Local Path) |
tempFiles | Array. | 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. |
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).
Type | Default value | Required | Description |
Array.<Object> | - | Yes | List of resources to be previewed. |
number | 0 | No | The sequence number of the currently displayed resource. |
boolean | true | No | Whether to display long-press menu. |
string | no-referrer | No | Origin: Sends the complete referrer. No-referrer: Not to send. The format is fixed as https://servicewechat.com/{appid}/{version}/page-frame.html , wherein {appid} represents the appid of the mini program. {version} is the version number of the mini program. A version number of 0 indicates a development version, trial version, or review version. A version number of devtools indicates a developer tool, and the rest are official versions. |
function | - | No | Callback Function of Successful Interface Call |
function | - | No | Callback Function of Failing Interface Call |
function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Type | Description |
Mini Program Code | - |
WeChat personal code at host client | Does not support mini games. |
WeCom personal code at host client | Does not support mini games. |
General Group Code | Exclusively includes WeChat user groups within the host client, not supporting mini games. |
Intercommunicating Group Code | Refers to groups within the host client that include both WeChat and WeCom users, not supporting mini games. |
WeChat Official Account QR Code. | Does not support mini games. |
This API is used via wx.saveImageToPhotosAlbum(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The image file path can be a temporary or permanent file path, not supporting 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) {},})
This API is used via wx.chooseMessageFile(Object object).
Attribute | Type | Default value | Required | Description |
count | number | - | Yes | The maximum number of files that can be selected ranges from 0 to 100. |
type | string | all | Yes | The type of the selected file, whose valid values are: all: Select from all files. video: Only video files can be selected. image: Only image files can be selected. file: Other files excluding images and videos can be selected. |
extension | Array.<string> | - | No | Filter based on file extension, effective only when type==file. Each item must not be an empty string. By default, no filtering is applied. |
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 |
tempFile | Array.<string> | Returns an array of local temporary file objects for the selected files. |
Structure attributes | Type | Description |
path | string | Local Temporary File Path (Local Path) |
size | number | Size of local temporary files, measured in bytes. |
name | string | Name of selected file |
type | string | Type of selected file, whose valid values include: video: Video files are selected. image: Image files are selected. file: Files excluding images and videos are selected. |
time | number | The sending time of the selected file's session, Unix timestamp. This attribute is currently not supported by the tool. |
Was this page helpful?