tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-02-24 17:10:36
Image
Last updated: 2025-02-24 17:10:36

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).
Notes:
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. 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).
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).
Notes:
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
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
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).
Notes:
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. 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).
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).
Notes:
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).
Notes:
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) {},
})


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

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon