my.compressImage

Compress large images to fulfill the size restrictions from some mini programs.

Parameters

Property

Type

Required

Description

apFilePaths

Array

Yes

An array of the image paths to be compressed.

compressLevel

int

No 

The image quality after the compress. Valid values are:

  • 0: Low quality
  • 1: Medium quality
  • 2: High quality
  • 4: The quality depends on the network. When the network is Wi-Fi, the image is compressed to the high-quality image. Otherwise, the image is compressed to the medium-quality image.

The default value is 4.

success

Function

No

The callback method that indicates a successful call.

fail

Function

No

The callback method that indicates a failed call.

complete

Function

No

The callback method that indicates the call is completed (this will be executed regardless of whether the call succeeds or fails).

Success callback function

Property

Type

Required

Description

apFilePaths

Array

Yes

The local file path of the compressed image.

Error code

Error Code

Error Message

Description

2

Compress failed

Failed to compress all images.

Invalid parameter

Failed to compress one of all images.