Skip to main content

Error Classes

FacebetterError

Facebetter error class, extends Error. Properties:
  • message: Error message
  • code: Error code (default -1)
  • name: Error name (fixed as ‘FacebetterError’)
Example:

Configuration Classes

EngineConfig

Engine configuration class, used to initialize the beauty engine. Constructor:
Parameters:
  • config.appId (string, optional): Application ID (required if licenseJson is not provided)
  • config.appKey (string, optional): Application key (required if licenseJson is not provided)
  • config.licenseJson (string, optional): License JSON string (if provided, appId and appKey are not needed)
  • config.externalContext (boolean, optional): Whether to use external OpenGL context (reserved for configuration structure alignment in Web/WASM environment, but currently not effective)
Methods:
  • isValid(): Validate if configuration is valid
  • toString(): Return string representation of configuration
Verification Priority:
  • If licenseJson is not empty, use license data verification (supports online response and offline license)
  • Otherwise, use appId and appKey for automatic online verification
Example:

Enumeration Types

BeautyType

Beauty type enumeration.

BasicParam

Basic beauty parameter enumeration.

ReshapeParam

Face reshape parameter enumeration.

MakeupParam

Makeup parameter enumeration.

LipstickStyle

Lipstick style enumeration.

BlushStyle

Blush style enumeration.

MirrorMode

Mirror mode enumeration, applied to input before processing.

Resource Management

  • setFilter(filterId): Set filter
    • Parameters: filterId (string) unique filter identifier. Pass an empty string to clear.
  • setFilterIntensity(intensity): Set filter intensity
    • Parameters: intensity (number) intensity value, range [0.0, 1.0].
  • setSticker(stickerId): Set sticker
    • Parameters: stickerId (string) unique sticker identifier. Pass an empty string to clear.
  • registerFilter(filterId, resource): Register filter
    • Parameters:
      • filterId (string): Unique filter identifier
      • resource (string|Uint8Array): Resource path (.fbd file) or Uint8Array data
  • registerSticker(stickerId, resource): Register sticker
    • Parameters:
      • stickerId (string): Unique sticker identifier
      • resource (string|Uint8Array): Resource path (.fbd file) or Uint8Array data
  • unregisterFilter(filterId): Unload filter
  • unregisterAllFilters(): Unload all filters
  • unregisterSticker(stickerId): Unload sticker
  • unregisterAllStickers(): Unload all stickers
  • getRegisteredFilters(): Get list of registered filters
    • Returns: string[]
  • getRegisteredStickers(): Get list of registered stickers
    • Returns: string[]

ProcessMode

Processing mode enumeration.

BackgroundMode

Background mode enumeration.

VirtualBackgroundOptions

Virtual background options class, used to set virtual background parameters. Constructor:
Parameters:
  • options (Object, optional): Options object
    • mode (BackgroundMode, optional): Background mode, defaults to BackgroundMode.None
    • backgroundImage (ImageData|HTMLImageElement|HTMLCanvasElement, optional): Background image, required when mode is Image
Methods:
  • isValid(): Validate if options are valid
    • Returns: boolean
    • When mode is Image, checks if backgroundImage exists
Example:

Engine Classes

BeautyEffectEngine

Main beauty effect engine class, provides entry point for beauty functionality. Constructor:
Parameters:
  • config (EngineConfig): Engine configuration object
Instance Methods:

Initialization

  • init(options): Initialize engine
    • Parameters:
      • options (Object, optional): Initialization options
        • timeout (number, optional): WASM module loading timeout in milliseconds, default 30000
        • authTimeout (number, optional): Online authentication timeout in milliseconds, default 10000
    • Returns: Promise<void>
    • Example:
  • setLogConfig(config): Set log configuration
    • Parameters:
      • config.consoleEnabled (boolean, optional): Enable console logging, default false
      • config.fileEnabled (boolean, optional): Enable file logging, default false (not supported in browser environment)
      • config.level (number, optional): Log level (0=DEBUG, 1=INFO, 2=WARN, 3=ERROR), default 0
      • config.fileName (string, optional): Log file name, default empty string
    • Returns: Promise<void>
    • Note: Can be called before or after init(), but recommended to call before init()

Parameter Settings

  • setBasicParam(param, value): Set basic beauty parameter
    • Parameters:
      • param (BasicParam): Parameter type
      • value (number): Parameter value, range [0.0, 1.0] (float)
    • Returns: void
    • Example: engine.setBasicParam(BasicParam.Whitening, 0.5);
  • setReshapeParam(param, value): Set face reshape parameter
    • Parameters:
      • param (ReshapeParam): Parameter type
      • value (number): Parameter value, range [0.0, 1.0] (float)
    • Returns: void
    • Example: engine.setReshapeParam(ReshapeParam.FaceThin, 0.5);
  • setMakeupParam(param, value): Set makeup parameter
    • Parameters:
      • param (MakeupParam): Parameter type
      • value (number): Parameter value, range [0.0, 1.0] (float)
    • Returns: void
    • Example: engine.setMakeupParam(MakeupParam.Lipstick, 0.5);
  • setLipstickStyle(style): Set lipstick style
    • Parameters:
      • style (LipstickStyle): Lipstick style
    • Returns: void
    • Example: engine.setLipstickStyle(LipstickStyle.Rouge);
  • setBlushStyle(style): Set blush style
    • Parameters:
      • style (BlushStyle): Blush style
    • Returns: void
    • Example: engine.setBlushStyle(BlushStyle.Classic);
  • setSkinOnlyBeauty(enabled): Set whether beauty is applied only to skin regions
    • Parameters:
      • enabled (boolean): true to enable skin-only beauty, false to apply to entire image
    • Returns: void
    • Example:
  • setVirtualBackground(options): Set virtual background (unified API, consistent with other platforms)
    • Parameters:
      • options (VirtualBackgroundOptions|Object): Virtual background options
        • mode (BackgroundMode): Background mode (None, Blur, Image)
        • backgroundImage (ImageData|HTMLImageElement|HTMLCanvasElement, optional): Background image (required when mode is Image)
    • Returns: void
    • Example:

Image Processing

  • processImage(input, width, height, frameType, mirrorMode): Process image
    • Parameters:
      • input (ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Uint8ClampedArray): Input image
      • width (number, optional): Image width (required when input is Uint8ClampedArray)
      • height (number, optional): Image height (required when input is Uint8ClampedArray)
      • frameType (FrameType, optional): Frame type, defaults to FrameType.Video
      • mirrorMode (MirrorMode, optional): Mirror mode applied to input before processing, defaults to MirrorMode.None
    • Returns: ImageData (synchronous return, not Promise)
    • Example:

Resource Management

  • destroy(): Destroy engine and release resources
    • Returns: void
    • Note: Call when engine is no longer needed to free memory and WASM resources
    • Example: engine.destroy();

Utility Functions

loadWasmModule

Load WASM module (usually not needed to call directly, engine handles automatically).

Usage Examples

Complete Example

Deprecated APIs

DeprecatedThe following APIs are deprecated.

Beauty Type Control

  • setBeautyTypeEnabled(beautyType, enabled)
    • Description: [Deprecated] Enable or disable beauty type (No effect in parameter-driven mode)
    • Return Value: void
  • isBeautyTypeEnabled(beautyType)
    • Description: [Deprecated] Check if beauty type is enabled (Always returns false)
    • Return Value: false
  • disableAllBeautyTypes()
    • Description: [Deprecated] Disable all beauty types (Please reset effects by zeroing parameters)
    • Return Value: void