Integrate SDK
Install via npm:
Using ES Module (Recommended):
Using CommonJS:
Log Configuration
Logging is disabled by default, you can enable it as needed:
Log configuration must be called before engine initialization.
Note: Log configuration must be called before engine initialization.
Create Engine Configuration
Follow the instructions on this page to get appId and appKey
Verification Priority:
- If
licenseJson is provided, use license data verification (supports online response and offline license)
- Otherwise, use
appId and appKey for automatic online verification
Error Handling
It’s recommended to check if engine creation is successful:
Adjust Beauty Parameters
All beauty parameters range from [0.0, 1.0]. Set to 0 to disable the effect.
Set Skin Beauty Parameters
Use setBasicParam interface to set skin beauty parameters, parameter range [0.0, 1.0] (float);
Supported skin beauty parameters:
Set Face Reshape Parameters
Use setReshapeParam interface to set face reshape parameters, parameter range [0.0, 1.0] (float);
Supported face reshape parameters:
Set Makeup Parameters
Use setMakeupParam interface to set makeup parameters, parameter range [0.0, 1.0] (float);
Supported makeup parameters:
Set Skin-Only Beauty
Use the setSkinOnlyBeauty interface to set whether beauty effects are applied only to skin regions. When enabled, beauty effects (smoothing, whitening, etc.) will only be applied to detected skin areas, leaving non-skin areas unchanged.
After enabling skin-only beauty, even with high beauty parameter values, non-skin areas (such as background, clothing, etc.) will not be affected.
Set Virtual Background
Enable virtual background via setVirtualBackground interface (unified API, consistent with other platforms):
Simplified syntax (also supported):
Using Filters and Stickers
Filter Functionality
Filters are set through the setFilter interface. Filter resource files (.fbd) must be registered via registerFilter first.
Sticker Functionality
Stickers are set through the setSticker interface and also need to be registered first.
Set Engine Callbacks
Monitor engine authentication and initialization status:
Event codes:
0: License validation success or engine initialization complete
1: License validation failed
101: Engine initialization failed
Process Images
Get Image Data from Canvas
Get Image Data from Image Element
Process Image
processMode includes Video and Image modes. Video is suitable for live streaming and video scenarios with higher efficiency, Image mode is suitable for image processing scenarios.
The engine automatically maintains input/output format consistency. If input is RGBA format, output is RGBA format; if input is I420 format, output is I420 format.
Draw Processed Image
Save Processed Image
Processed image data can be saved as image files:
Method 1: Using Canvas.toDataURL()
Method 2: Using Canvas.toBlob()
Method 3: Save as Different Formats
Complete Example: Save Processed Image
Lifecycle Management
Call destroy() method after engine use to release resources and avoid memory leaks.
Release Resources
When page unloads or no longer in use, be sure to release engine resources:
Memory Management
- Release unused ImageData objects promptly
- Avoid repeatedly creating large numbers of image objects in loops
- Recommend reusing Canvas and ImageData objects
- Best Practices - Performance optimization and architecture design recommendations
- FAQ - Common questions and troubleshooting
- API Reference - Complete API documentation