tencent cloud

Last updated: 2025-06-06 19:00:43
Image
Last updated: 2025-06-06 19:00:43

chooseImage

This API is called using wx.chooseImage(Object object).
Feature description:Allows users to select images from the local photo album or take photos using the camera.
Parameter and description: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)
object.success callback function parameter:Object res.
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.
res.tempFiles structure
Property
Type
Description
path
string
Local temporary file path.
size
number
Size of the local temporary file in bytes.
Example:
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 image
const tempFilePaths = res.tempFilePaths
}
})

compressImage

This API is called using wx.compressImage(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Compresses an image with optional compression quality settings.
Parameter and description: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 ranges from 0 to 100. A lower value results in lower quality and higher compression rate (applicable only to 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)
object.success callback function parameter:Object res.
Property
Type
Description
tempFilePath
string
The local temporary file path of the compressed image.
Example:
wx.compressImage({
src: '', // Image path
quality: 80 // Compression quality
})

getImageInfo

This API is called using wx.getImageInfo(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Gets image information. For network images, the download domain must be configured first.
Parameter and description: 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)
object.success callback function parameter:Object res.
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
The orientation of the device when the photo was taken.
type
string
Image format.
Valid values for res.orientation
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.
Valid values for res.type
Valid value
Description
unknown
Unknown format.
jpeg
JPEG compressed format.
png
PNG compressed format.
gif
GIF compressed format.
tiff
TIFF compressed format.
Example:
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

This API is called using wx.previewImage(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Allows users to preview images in full screen on a new page. During the preview, users can save the image, send it to friends, and perform other actions.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
urls
Array.<string>
-
True
List of image URLs to preview. Supports cloud file IDs.
current
string
The first URL
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)
Example:
wx.previewImage({
current: '', // The URL of the currently displayed image
urls: [], // List of image URLs to preview
})

previewMedia

This API is called using wx.previewMedia(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Allows users to preview images and videos.
Parameter and description: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)

saveImageToPhotosAlbum

This API is called using wx.saveImageToPhotosAlbum(Object object).
Note:
This API is supported in mini programs but not in mini games.
Requires user authorization for scope.writePhotosAlbum.
Feature description:Saves an image to the system album.
Parameter and description: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)
Example:
wx.saveImageToPhotosAlbum({
success(res) {},
})

chooseMessageFile

This API is called using wx.chooseMessageFile(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Selects a file from the client session.
Parameter and description:Object object.
Property
Type
Valid values and description
Default value
‍Required
Description
count
number
-
-
True
The maximum number of files that can be selected. Value range: 0 to 100.
type
string
all: Select from all files
video: Only select video files
image: Only select image files
file: Select other files excluding images and videos
'all'
False
Type of files to be selected.
extension
Array.<string>
-
-
False
Filters by file extension, valid only when type==file. Each item must not be an empty string. No filtering by default.
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)

chooseExternalFile

This API is called using wx.chooseExternalFile(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Selects a file from the mobile file picker.
Parameter and description:Object object.
Property
Type
Valid values and description
Default value
‍Required
Description
count
number
-
-
True
The maximum number of files that can be selected. Value range: 0 to 100.
type
string
all: Select from all files
video: Only select video files
image: Only select image files
file: Select other files excluding images and videos
'all'
False
Type of files to be selected.
extension
Array.<string>
-
-
False
Filters by file extension, valid only when type==file. Each item must not be an empty string. No filtering by default.
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)

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback