This API is called using wx.chooseImage(Object object).
Property | Type | Valid values and description | Default value | Required | Description |
count | number | - | 9 | False | The maximum number of images that can be selected. |
sizeType | Array.<string> | original: Full size image compressed: Compressed image | ['original', 'compressed'] | False | The size of the selected images. |
sourceType | Array.<string> | album: Select images from the album camera: Use the camera | ['album', 'camera'] | False | The source of the images. |
success | function | - | - | False | Callback function for successful API calls. |
fail | function | - | - | False | Callback function for failed API calls. |
complete | function | - | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
tempFilePaths | Array.<string> | List of local temporary file paths for the images. |
tempFiles | Array.<Object> | List of local temporary files for the images. |
Property | Type | Description |
path | string | Local temporary file path. |
size | number | Size of the local temporary file in bytes. |
wx.chooseImage({count: 1,sizeType: ['original', 'compressed'],sourceType: ['album', 'camera'],success (res) {// tempFilePath can be used as the src attribute of an img tag to display the imageconst tempFilePaths = res.tempFilePaths}})
This API is called using wx.compressImage(Object object).
Property | Type | Default value | Required | Description |
src | string | - | True | The path of the image, supports local paths and code package paths. |
quality | number | 80 | False | Compression quality. Value range: 0-100. The smaller the value, the lower the quality and the higher the compression rate (only valid for jpg). |
compressedWidth | number | - | False | The width of the compressed image in px. If not specified, it will scale proportionally based on compressedHeight. |
compressedHeight | number | - | False | The height of the compressed image in px. If not specified, it will scale proportionally based on compressedWidth. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
tempFilePath | string | The local temporary file path of the compressed image. |
wx.compressImage({src: '', // Image pathquality: 80 // Compression quality})
This API is called using wx.getImageInfo(Object object).
Property | Type | Default value | Required | Description |
src | string | - | True | The path of the image, which can be a relative path, temporary file path, storage file path, or network image path. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
width | number | The original width of the image in px. Rotation is not considered. |
height | number | The original height of the image in px. Rotation is not considered. |
path | string | The local path of the image. |
orientation | string | |
type | string | Image format. |
Value | Description |
up | Default orientation (phone held horizontally), corresponds to Exif 1, or no orientation information. |
up-mirrored | Same as up, but mirrored, corresponds to Exif 2. |
down | Rotates 180 degrees, corresponds to Exif 3. |
down-mirrored | Same as down, but mirrored, corresponds to Exif 4. |
left-mirrored | Same as left, but mirrored, corresponds to Exif 5. |
right | Rotated 90 degrees clockwise, corresponds to Exif 6. |
right-mirrored | Same as right, but mirrored, corresponds to Exif 7. |
left | Rotated 90 degrees counterclockwise, corresponds to Exif 8. |
Value | Description |
unknown | Unknown format. |
jpeg | JPEG compressed format. |
png | PNG compressed format. |
gif | GIF compressed format. |
tiff | TIFF compressed 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 called using wx.previewImage(Object object).
Property | Type | Default value | Required | Description |
urls | Array.<string> | - | True | List of image URLs to preview. Cloud file IDs are supported. |
current | string | First image in urls | False | The URL of the currently displayed image. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.previewImage({current: '', // The URL of the currently displayed imageurls: [], // List of image URLs to preview})
This API is called using wx.previewMedia(Object object).
Property | Type | Default value | Required | Description |
sources | Array.<Object> | | True | List of resources to preview. |
current | number | 0 | False | The index of the currently displayed resource. |
success | function | | False | Callback function for successful API calls. |
fail | function | | False | Callback function for failed API calls. |
complete | function | | False | Callback function executed after API call ends (regardless of success or failure). |
This API is called using wx.saveImageToPhotosAlbum(Object object).
Property | Type | Default value | Required | Description |
filePath | string | - | True | Image file path, which can be a temporary file path or a permanent file path (local path). Network image paths are not supported. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.saveImageToPhotosAlbum({success(res) {},})