facebetter 1.5.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,7 @@ Facebetter is a high-performance, cross-platform SDK for real-time face beauty a
20
20
  - **Precise Face Reshaping**: Comprehensive adjustments for face thinning, V-shape, eye enlargement, nose slimming, and chin/forehead contouring.
21
21
  - **Professional Makeup**: Real-time application of lipstick, blush, and more with parametric intensity control.
22
22
  - **AI Virtual Background**: High-precision portrait segmentation for background blur and custom image replacement.
23
- - **Premium Effects**: Includes 20+ real-time filters, animated stickers (in development), and professional-grade Chroma Key (Green Screen) removal.
23
+ - **Premium Effects**: Includes 20+ real-time filters, 2D stickers, and professional-grade Chroma Key (Green Screen) removal.
24
24
  - **Developer Friendly**: Clean, well-documented JS API. Integrated in minutes with support for various input sources (Image, Video, Canvas, ImageData).
25
25
  - **Cross-Platform Consistency**: Shared core algorithms with Android, iOS, and Desktop SDKs ensure a unified experience across all devices.
26
26
 
@@ -36,38 +36,53 @@ Ideal for modern frontend environments like Vite, Webpack, React, or Vue.
36
36
  npm install facebetter
37
37
  ```
38
38
 
39
+ This installs `facebetter-core` as well (declared as `facebetter-core` `^<same version>`). Do not add `facebetter-core` to your app unless you have a reason to import the runtime directly.
40
+
39
41
  ### via CDN
40
42
 
41
43
  For direct browser usage.
42
44
 
43
45
  ```html
44
- <!-- Import SDK via CDN -->
45
46
  <script src="https://cdn.jsdelivr.net/npm/facebetter/dist/facebetter.js"></script>
46
47
  ```
47
48
 
49
+ The UMD build loads `facebetter-core` from the **same directory** as `facebetter.js`. A single jsDelivr URL for `facebetter` is not enough: also host `facebetter-core.js` next to it (from the `facebetter-core` package `dist/`), or use npm + a bundler.
50
+
48
51
  ---
49
52
 
50
53
  ## 🚀 Quick Start
51
54
 
52
55
  ### 1. Initialize the Engine
53
56
 
54
- Facebetter supports both online activation via `appId` / `appKey` and offline activation via `licenseJson`.
57
+ Web 必须联网校验。`EngineConfig` **没有** `appId` / `appKey`:生产环境由你的服务器保管密钥并代理鉴权。本地调试、或你确认环境不会泄露密钥时,可以在调用处直连 Cloudflare。
55
58
 
56
59
  ```javascript
57
- import { BeautyEffectEngine, EngineConfig } from 'facebetter';
60
+ import {
61
+ BeautyEffectEngine,
62
+ EngineConfig,
63
+ createDirectAuthFetcher,
64
+ } from 'facebetter';
65
+
66
+ // 方式 A:你的后端已经拿到 v2 token(compact JWS 或 {success, token})
67
+ const config = new EngineConfig({
68
+ licenseToken: await fetch('/api/facebetter/auth', { method: 'POST' }).then((r) => r.text()),
69
+ });
70
+
71
+ // 方式 B:把 WASM 的 nonce challenge 转发到你的后端(生产推荐)
72
+ const config = new EngineConfig({
73
+ authProxyUrl: '/api/facebetter/auth',
74
+ });
58
75
 
59
- // 1. Configure the engine
76
+ // 方式 C:本地调试 / 无自己的服务器时,调用处直连 Cloudflare(密钥会出现在前端,不要用于生产)
60
77
  const config = new EngineConfig({
61
- appId: 'YOUR_APP_ID',
62
- appKey: 'YOUR_APP_KEY',
63
- // Or use offline license
64
- // licenseJson: '{...}'
78
+ fetchAuthResponse: createDirectAuthFetcher({
79
+ appId: 'your-app-id',
80
+ appKey: 'your-app-key',
81
+ }),
65
82
  });
66
83
 
67
- // 2. Create engine instance
68
84
  const engine = new BeautyEffectEngine(config);
69
85
 
70
- // 3. Initialize (Loads WASM resources and performs authentication)
71
86
  try {
72
87
  await engine.init();
73
88
  console.log('Facebetter Engine initialized successfully');
@@ -76,19 +91,46 @@ try {
76
91
  }
77
92
  ```
78
93
 
79
- ### 2. Configure Beauty Parameters
94
+ 客户服务器代理示例(Node):
80
95
 
81
96
  ```javascript
82
- import { BeautyType, BasicParam, ReshapeParam } from 'facebetter';
97
+ import { createHmac } from 'node:crypto';
98
+
99
+ app.post('/api/facebetter/auth', async (req, res) => {
100
+ const { nonce, timestamp, platform, user_agent } = req.body;
101
+ const appId = process.env.FB_APP_ID;
102
+ const appKey = process.env.FB_APP_KEY;
103
+ const payload = `v2|${appId}|${timestamp}|${nonce}|${platform}`;
104
+ const hmac = createHmac('sha256', appKey).update(payload).digest('hex');
105
+
106
+ const upstream = await fetch('https://facebetter.pixpark.net/facebetter/v2/auth', {
107
+ method: 'POST',
108
+ headers: { 'Content-Type': 'application/json' },
109
+ body: JSON.stringify({
110
+ app_id: appId,
111
+ hmac_signature: hmac,
112
+ timestamp,
113
+ nonce,
114
+ platform,
115
+ user_agent,
116
+ }),
117
+ });
118
+ res.status(upstream.status).send(await upstream.text());
119
+ });
120
+ ```
121
+
122
+ iOS / Android 仍可用 `appId` + `appKey` 直连在线鉴权,或使用绑定 Bundle ID / Package Name 的离线 license。Web 不支持离线 license。
83
123
 
84
- // Enable specific beauty modules
85
- engine.setBeautyTypeEnabled(BeautyType.Basic, true); // Basic skin retouching
86
- engine.setBeautyTypeEnabled(BeautyType.Reshape, true); // Face reshaping
124
+
125
+ ### 2. Configure Beauty Parameters
126
+
127
+ ```javascript
128
+ import { Reshape } from 'facebetter';
87
129
 
88
130
  // Set skin smoothing intensity (0.0 - 1.0)
89
- engine.setBasicParam(BasicParam.Smoothing, 0.8);
131
+ engine.setSmoothing(0.8);
90
132
  // Set eye enlargement intensity (0.0 - 1.0)
91
- engine.setReshapeParam(ReshapeParam.EyeSize, 0.5);
133
+ engine.setReshape(Reshape.EyeSize, 0.5);
92
134
  ```
93
135
 
94
136
  ### 3. Process Video Stream
@@ -123,14 +165,35 @@ processFrame();
123
165
  | Method | Description |
124
166
  | :--- | :--- |
125
167
  | `init()` | Asynchronously initializes the engine and loads assets. |
126
- | `setBeautyTypeEnabled(type, enabled)` | Toggle specific modules (Basic, Reshape, Makeup, Background). |
127
- | `setBasicParam(param, value)` | Adjust skin retouching settings (Smoothing, Whitening, etc.). |
128
- | `setReshapeParam(param, value)` | Adjust face reshaping settings (Thinning, Eye Size, etc.). |
129
- | `setMakeupParam(param, value)` | Adjust makeup intensity (Lipstick, Blush, etc.). |
130
- | `setLipstickStyle(style)` | Switch lipstick style (Rouge / Coral / Pink). |
131
- | `setBlushStyle(style)` | Switch blush style (Classic / Peach / Rose). |
132
- | `setFilter(path, intensity)` | Apply a LUT filter with custom intensity. |
133
- | `setVirtualBackground(options)` | Configure background blur or image replacement. |
168
+ | `setSmoothing(value)` | Set skin smoothing intensity. |
169
+ | `setSmoothingStyle(style)` | Switch smoothing style. |
170
+ | `setWhitening(value)` | Set skin whitening intensity. |
171
+ | `setWhiteningStyle(style)` | Switch whitening style. |
172
+ | `setSharpening(value)` | Set image sharpening intensity. |
173
+ | `setRosiness(value)` | Set skin rosiness intensity. |
174
+ | `setReshape(param, value)` | Adjust face reshaping settings (Thinning, Eye Size, etc.). |
175
+ | `setLipstick(value)` | Set lipstick intensity. |
176
+ | `setLipstickColor(style)` | Switch lipstick colour preset. |
177
+ | `setBlush(value)` | Set blush intensity. |
178
+ | `setBlushStyle(style)` / `setBlushColor(color)` | Switch blush style / colour. |
179
+ | `setContour(value)` | Set contour intensity. |
180
+ | `setContourStyle(style)` | Switch contour / highlight map. |
181
+ | `setEyeShadow(value)` | Set eyeshadow intensity. |
182
+ | `setEyeShadowStyle` / `setEyeShadowColor` | Eyeshadow style / colour. |
183
+ | `setEyeLiner(value)` | Set eyeliner intensity. |
184
+ | `setEyeLinerStyle` / `setEyeLinerColor` | Eyeliner style / colour. |
185
+ | `setEyebrow(value)` | Set eyebrow intensity. |
186
+ | `setEyebrowStyle` / `setEyebrowColor` | Eyebrow style / colour. |
187
+ | `setEyelash(value)` | Set eyelash intensity. |
188
+ | `setEyelashStyle` / `setEyelashColor` | Eyelash style / colour. |
189
+ | `setPupil(value)` | Set pupil intensity. |
190
+ | `setPupilColor(style)` | Switch contact-lens colourway. |
191
+ | `setFilter(path or Uint8Array)` | Apply a LUT filter from an .fbd path or in-memory bytes. |
192
+ | `clearFilter()` | Remove the current LUT filter. |
193
+ | `setFilterIntensity(intensity)` | Set the current filter intensity [0.0, 1.0]. |
194
+ | `setVirtualBackgroundBlur(level)` | Enable background blur. Level [0, 1] is continuous; 0 clears it. |
195
+ | `setVirtualBackground(path or Uint8Array)` | Replace the background with a png/jpg path or encoded bytes. |
196
+ | `clearVirtualBackground()` | Turn off virtual background. |
134
197
  | `processImage(source)` | Process an input source (Image, Video, Canvas, or ImageData). |
135
198
  | `destroy()` | Clean up resources and release WebAssembly memory. |
136
199
 
@@ -138,7 +201,7 @@ processFrame();
138
201
 
139
202
  ## ⚠️ Important Notes
140
203
 
141
- 1. **WASM Asset Path**: By default, the SDK expects WASM and asset bundles in the `/facebetter/` directory. Ensure your static asset server is configured correctly.
204
+ 1. **Runtime package**: `import('facebetter-core')` is resolved by your bundler from `node_modules` (installed with `facebetter`). For a `<script>` tag, place `facebetter-core.js` beside `facebetter.js`.
142
205
  2. **Secure Context**: The SDK requires a Secure Context (HTTPS or localhost) to access modern browser features.
143
206
  3. **Performance Optimization**:
144
207
  - Always call `processImage` within a `requestAnimationFrame` loop.