facebetter 1.5.1 → 2.0.1

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,47 @@ 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`. Host these next to `facebetter.js`:
50
+
51
+ - `facebetter-core.js`
52
+ - `facebetter-core.wasm`
53
+ - `resource.fbd`
54
+
55
+ A single jsDelivr URL for `facebetter` is not enough. npm + a bundler is simpler.
56
+
48
57
  ---
49
58
 
50
59
  ## 🚀 Quick Start
51
60
 
52
61
  ### 1. Initialize the Engine
53
62
 
54
- Facebetter supports both online activation via `appId` / `appKey` and offline activation via `licenseJson`.
63
+ Web 必须联网校验。`EngineConfig` **没有** `appId` / `appKey`:由你的服务器换 token,再传入 `licenseToken`。
55
64
 
56
65
  ```javascript
57
- import { BeautyEffectEngine, EngineConfig } from 'facebetter';
58
-
59
- // 1. Configure the engine
60
- const config = new EngineConfig({
61
- appId: 'YOUR_APP_ID',
62
- appKey: 'YOUR_APP_KEY',
63
- // Or use offline license
64
- // licenseJson: '{...}'
66
+ import {
67
+ BeautyEffectEngine,
68
+ EngineConfig,
69
+ } from 'facebetter';
70
+
71
+ const licenseToken = await fetch('/api/facebetter/auth', {
72
+ method: 'POST',
73
+ }).then((r) => {
74
+ if (!r.ok) throw new Error(`auth failed: ${r.status}`);
75
+ return r.text();
65
76
  });
66
77
 
67
- // 2. Create engine instance
68
- const engine = new BeautyEffectEngine(config);
78
+ const engine = new BeautyEffectEngine(new EngineConfig({ licenseToken }));
69
79
 
70
- // 3. Initialize (Loads WASM resources and performs authentication)
71
80
  try {
72
81
  await engine.init();
73
82
  console.log('Facebetter Engine initialized successfully');
@@ -76,19 +85,59 @@ try {
76
85
  }
77
86
  ```
78
87
 
79
- ### 2. Configure Beauty Parameters
88
+ #### 服务端代理(Node)
89
+
90
+ 密钥只放在服务器环境变量。签名串为 `v2|{app_id}|{timestamp}|{nonce}|web`,HMAC-SHA256(hex)后请求上游,把**响应原文**返回给前端:
80
91
 
81
92
  ```javascript
82
- import { BeautyType, BasicParam, ReshapeParam } from 'facebetter';
93
+ import { createHmac, randomBytes } from 'node:crypto';
94
+
95
+ const AUTH_URL = 'https://facebetter.pixpark.net/facebetter/v2/auth';
96
+
97
+ app.post('/api/facebetter/auth', async (req, res) => {
98
+ const appId = process.env.FB_APP_ID;
99
+ const appKey = process.env.FB_APP_KEY;
100
+ if (!appId || !appKey) {
101
+ res.status(500).json({ error: 'FB_APP_ID / FB_APP_KEY not configured' });
102
+ return;
103
+ }
83
104
 
84
- // Enable specific beauty modules
85
- engine.setBeautyTypeEnabled(BeautyType.Basic, true); // Basic skin retouching
86
- engine.setBeautyTypeEnabled(BeautyType.Reshape, true); // Face reshaping
105
+ const nonce = randomBytes(16).toString('hex');
106
+ const timestamp = Math.floor(Date.now() / 1000);
107
+ const platform = 'web';
108
+ const payload = `v2|${appId}|${timestamp}|${nonce}|${platform}`;
109
+ const hmac = createHmac('sha256', appKey).update(payload).digest('hex');
110
+
111
+ const upstream = await fetch(AUTH_URL, {
112
+ method: 'POST',
113
+ headers: { 'Content-Type': 'application/json' },
114
+ body: JSON.stringify({
115
+ app_id: appId,
116
+ hmac_signature: hmac,
117
+ timestamp,
118
+ nonce,
119
+ platform,
120
+ user_agent: req.headers['user-agent'] || '',
121
+ }),
122
+ });
123
+ res.status(upstream.status).send(await upstream.text());
124
+ });
125
+ ```
126
+
127
+ 可运行参考:[Demo `api/facebetter/auth.js`](https://github.com/pixpark/facebetter-sdk/blob/main/demo/web/react/api/facebetter/auth.js)。完整说明见 [Auth & License](https://facebetter.net/docs/intro/license)。
128
+
129
+ iOS / Android 仍可用 `appId` + `appKey` 直连在线鉴权,或使用绑定 Bundle ID / Package Name 的离线 license。Web 不支持离线 license。
130
+
131
+
132
+ ### 2. Configure Beauty Parameters
133
+
134
+ ```javascript
135
+ import { Reshape } from 'facebetter';
87
136
 
88
137
  // Set skin smoothing intensity (0.0 - 1.0)
89
- engine.setBasicParam(BasicParam.Smoothing, 0.8);
138
+ engine.setSmoothing(0.8);
90
139
  // Set eye enlargement intensity (0.0 - 1.0)
91
- engine.setReshapeParam(ReshapeParam.EyeSize, 0.5);
140
+ engine.setReshape(Reshape.EyeSize, 0.5);
92
141
  ```
93
142
 
94
143
  ### 3. Process Video Stream
@@ -123,14 +172,35 @@ processFrame();
123
172
  | Method | Description |
124
173
  | :--- | :--- |
125
174
  | `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. |
175
+ | `setSmoothing(value)` | Set skin smoothing intensity. |
176
+ | `setSmoothingStyle(style)` | Switch smoothing style. |
177
+ | `setWhitening(value)` | Set skin whitening intensity. |
178
+ | `setWhiteningStyle(style)` | Switch whitening style. |
179
+ | `setSharpening(value)` | Set image sharpening intensity. |
180
+ | `setRosiness(value)` | Set skin rosiness intensity. |
181
+ | `setReshape(param, value)` | Adjust face reshaping settings (Thinning, Eye Size, etc.). |
182
+ | `setLipstick(value)` | Set lipstick intensity. |
183
+ | `setLipstickColor(style)` | Switch lipstick colour preset. |
184
+ | `setBlush(value)` | Set blush intensity. |
185
+ | `setBlushStyle(style)` / `setBlushColor(color)` | Switch blush style / colour. |
186
+ | `setContour(value)` | Set contour intensity. |
187
+ | `setContourStyle(style)` | Switch contour / highlight map. |
188
+ | `setEyeShadow(value)` | Set eyeshadow intensity. |
189
+ | `setEyeShadowStyle` / `setEyeShadowColor` | Eyeshadow style / colour. |
190
+ | `setEyeLiner(value)` | Set eyeliner intensity. |
191
+ | `setEyeLinerStyle` / `setEyeLinerColor` | Eyeliner style / colour. |
192
+ | `setEyebrow(value)` | Set eyebrow intensity. |
193
+ | `setEyebrowStyle` / `setEyebrowColor` | Eyebrow style / colour. |
194
+ | `setEyelash(value)` | Set eyelash intensity. |
195
+ | `setEyelashStyle` / `setEyelashColor` | Eyelash style / colour. |
196
+ | `setPupil(value)` | Set pupil intensity. |
197
+ | `setPupilColor(style)` | Switch contact-lens colourway. |
198
+ | `setFilter(path or Uint8Array)` | Apply a LUT filter from an .fbd path or in-memory bytes. |
199
+ | `clearFilter()` | Remove the current LUT filter. |
200
+ | `setFilterIntensity(intensity)` | Set the current filter intensity [0.0, 1.0]. |
201
+ | `setVirtualBackgroundBlur(level)` | Enable background blur. Level [0, 1] is continuous; 0 clears it. |
202
+ | `setVirtualBackground(path or Uint8Array)` | Replace the background with a png/jpg path or encoded bytes. |
203
+ | `clearVirtualBackground()` | Turn off virtual background. |
134
204
  | `processImage(source)` | Process an input source (Image, Video, Canvas, or ImageData). |
135
205
  | `destroy()` | Clean up resources and release WebAssembly memory. |
136
206
 
@@ -138,7 +208,7 @@ processFrame();
138
208
 
139
209
  ## ⚠️ Important Notes
140
210
 
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.
211
+ 1. **Runtime package**: `import('facebetter-core')` is resolved by your bundler from `node_modules` (installed with `facebetter`). The SDK then downloads `facebetter-core.wasm` and `resource.fbd` from that package. For a `<script>` tag, place `facebetter-core.js`, `facebetter-core.wasm`, and `resource.fbd` beside `facebetter.js`. Pass `onProgress` to `init()` for download progress.
142
212
  2. **Secure Context**: The SDK requires a Secure Context (HTTPS or localhost) to access modern browser features.
143
213
  3. **Performance Optimization**:
144
214
  - Always call `processImage` within a `requestAnimationFrame` loop.