HomeDocs
Skip to main content

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

PropertyTypeDefaultRequiredDescription
srcstringYesPath of the image; supports local path, code package path
qualitynumber80NoCompression quality, range 0 ~ 100, the smaller the value, the lower the quality and the higher the compression ratio
compressedWidthnumberNoWidth of the compressed image in pixels, if not filled, it will be scaled proportionally based on compressedHeight
compressedHeightnumberNoHeight of the compressed image in pixels, if not filled, it will be scaled proportionally based on compressedWidth
successfunctionNoCallback function for a successful API call
failfunctionNoCallback function for a failed API call
completefunctionNoCallback function that will be executed when the API call ends (both success and failure)

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue-Set successfully.
tempFilePathstringTemporary file path of the compressed image (local path)

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstring1. Parameter error: AS10001
2. Quality must be 0..100: CI10002
3. 3. Original file not exists: CI10003
successstringfalse-Set failed.

Sample Code

// pages/index/index.js
Page({
compressImage() {
dlt.compressImage({
src: "", // 图片路径
quality: 80, // 压缩质量
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.