title: Taro.compressImage(option)
sidebar_label: compressImage
Compresses images. Multiple types of compression quality are available.
Reference
Type
(option: Option) => Promise<SuccessCallbackResult>
Parameters
Option
| Property |
Type |
Required |
Description |
| src |
string |
Yes |
The path to the image. It can be a relative path, a temporary file path, or a file storage path. |
| quality |
number |
No |
Compression quality. The value range is 0-100. A smaller value indicates poorer quality and higher compression rate (only for jpg). |
| complete |
(res: any) => void |
No |
The callback function used when the API call completed (always executed whether the call succeeds or fails) |
| fail |
(res: any) => void |
No |
The callback function for a failed API call |
| success |
(res: Result) => void |
No |
The callback function for a successful API call |
SuccessCallbackResult
| Property |
Type |
Description |
| tempFilePath |
string |
The temporary file path to the compressed image |
| errMsg |
string |
Call result |
Sample Code
Taro.compressImage({ src: '', // Path to the image quality: 80 // Compression quality})
API Support
| API |
WeChat Mini-Program |
H5 |
React Native |
| Taro.compressImage |
✔️ |
|
✔️ |