Image
chooseImage
TIP
The API usage is as follows: wx.chooseImage(Object object)
Functional description: Select an image from the local album or take a photo with the camera.
Parameters and descriptions: Object object
Properties Type Legal values Default value Required Description count number - 9 No The maximum number of images that can be selected sizeType Array.< string>original:Original image
compressed:Compressed image['original', 'compressed'] No The size of the selected image sourceType Array.< string>album:Original image
camera:Compressed image['album', 'camera'] No Select the source of the image success Function - - No Callback function for successful interface call fail Function - - No Callback function for failed interface call complete Function - - No Callback function for interface call completion (executed regardless of success or failure) object.success callback function parameters: Object res。
Properties Type Description tempFilePaths Array.< string>List of local temporary file paths for images (local path) tempFiles Array.< Object>List of local temporary files for images Structure of res.tempFiles
Properties Type Description path string Local temporary file path size number Local temporary file size, unit B Sample code:
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 image
const tempFilePaths = res.tempFilePaths
}
})compressImage
TIP
The API usage is as follows: wx.compressImage(Object object)
This API is supported by mini programs, but not by mini games.
Functional description: Compress the image interface, with optional compression quality.
Parameters and descriptions: Object object
Properties Type Default value Required Description src string - Yes Image path, support network images, temporary paths, code package paths quality number 80 No Compression quality, range 0~100, the smaller the value, the lower the quality and the higher the compression rate (only valid for jpg) compressedWidth number - No The width of the compressed image, in px, if not filled in, it will be proportionally scaled by compressedHeight by default compressedHeight number - No The height of the compressed image, in px, if not filled in, it will be proportionally scaled by compressedWidth by default success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) object.success callback function parameters: Object res。
Properties Type Description tempFilePath string The temporary file path of the compressed image (local path) Sample code:
wx.compressImage({
src: '', // Image path
quality: 80 // Compression quality
})getImageInfo
TIP
The API usage is as follows: wx.getImageInfo(Object object)
This API is supported by mini programs, but not by mini games.
Functional description: Get image information, network images must first configure the download domain name to take effect
Parameters and descriptions: Object object
Properties Type Default value Required Description src string - Yes The path of the image can be a relative path, temporary file path, storage file path, network image path success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) object.success callback function parameters: Object res。
Properties Type Description width number The original width of the image, in px, regardless of rotation height number The original height of the image, in px, regardless of rotation path string The local path of the image orientation string Device orientation when taking pictures type string Image format res.orientationLegal value
Value Description up Default orientation (taking pictures with the phone held horizontally), corresponding to 1 in Exif, or no orientation information up-mirrored Same as up, but mirrored, corresponding to 2 in Exif down Rotate 180 degrees, corresponding to 3 in Exif down-mirrored Same as down, but mirror flipped, corresponding to 4 in Exif left-mirrored Same as left, but mirror flipped, corresponding to 5 in Exif right 93 degrees clockwise rotation, corresponding to 6 in Exif right-mirrored Same as right, but mirror flipped, corresponding to 7 in Exif left 93 degrees counterclockwise rotation, corresponding to 8 in Exif res.typeLegal value
Value Description unknown Unknown format jpeg jpeg compression format png png compression format gif gif compression format tiff tiff compression format Sample code:
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)
},
})
},
})previewImage
TIP
The API usage is as follows: wx.previewImage(Object object)
This API is supported by mini programs, but not by mini games.
Functional description: Preview the image in full screen in a new page. During the preview, users can save the image, send it to friends, etc.
Parameters and descriptions: Object object
Properties Type Default value Required Description urls Array.< string>- Yes List of image links to be previewed. Supports cloud file ID current string The first of urls No Link of the currently displayed image success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) Sample code:
wx.previewImage({
current: '', // The HTTP link to the currently displayed image.
urls: [], // List of HTTP image links to be previewed.
})previewMedia
TIP
The API usage is as follows: wx.previewMedia(Object object)
This API is supported by mini programs, but not by mini games.
Functional description: Preview pictures and videos.
Parameters and descriptions: Object object
Properties Type Default value Required Description sources Array.< Object>- Yes List of resources to be previewed current number 0 No The currently displayed resource number success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure)
saveImageToPhotosAlbum
TIP
The API usage is as follows: wx.saveImageToPhotosAlbum(Object object)
This API is supported by mini programs, but not by mini games.
TIP
User authorization is required before calling scope.writePhotosAlbum
Functional description: Save the image to the system album.
Parameters and descriptions: Object object
Properties Type Default value Required Description filePath string - Yes 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 - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) Sample code:
wx.saveImageToPhotosAlbum({
success(res) {},
})