title: Taro.compressImage(option)

sidebar_label: compressImage

Compresses images. Multiple types of compression quality are available.

Reference

Type

  1. (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

  1. Taro.compressImage({
  2. src: '', // Path to the image
  3. quality: 80 // Compression quality
  4. })

API Support

API WeChat Mini-Program H5 React Native
Taro.compressImage ✔️ ✔️