dlt.compressImage
Introduction
Image compression interface, with optional compression quality.
Usage Restrictions
Supported by the base library version 3.0.0
or higher.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
src | string | Yes | Path of the image; supports local path, code package path | |
quality | number | 80 | No | Compression quality, range 0 ~ 100, the smaller the value, the lower the quality and the higher the compression ratio |
compressedWidth | number | No | Width of the compressed image in pixels, if not filled, it will be scaled proportionally based on compressedHeight | |
compressedHeight | number | No | Height of the compressed image in pixels, if not filled, it will be scaled proportionally based on compressedWidth | |
success | function | No | Callback function for a successful API call | |
fail | function | No | Callback function for a failed API call | |
complete | function | No | Callback function that will be executed when the API call ends (both success and failure) |
object.success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true-Set successfully. |
tempFilePath | string | Temporary file path of the compressed image (local path) |
object.fail Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
errMsg | string | 1. Parameter error: AS10001 2. Quality must be 0..100: CI10002 3. 3. Original file not exists: CI10003 |
success | string | false-Set failed. |
Sample Code
// pages/index/index.js
Page({
compressImage() {
dlt.compressImage({
src: "", // 图片路径
quality: 80, // 压缩质量
});
},
});