@xuda.io/account_module 1.2.243 → 1.2.244
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/index.mjs +20 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
-
import {
|
|
3
|
+
import { removeBackground } from '@imgly/background-removal-node';
|
|
4
|
+
import fs from 'node:fs';
|
|
4
5
|
|
|
5
6
|
global._conf = (
|
|
6
7
|
await import(path.join(process.env.XUDA_HOME, process.env.XUDA_CONFIG), {
|
|
@@ -1544,3 +1545,21 @@ export const get_user_name = async function (uid) {
|
|
|
1544
1545
|
return 'unknown';
|
|
1545
1546
|
}
|
|
1546
1547
|
};
|
|
1548
|
+
|
|
1549
|
+
const removeBg = async function (inputPath, outputPath) {
|
|
1550
|
+
try {
|
|
1551
|
+
// Load image from file
|
|
1552
|
+
const imageBuffer = fs.readFileSync(inputPath);
|
|
1553
|
+
|
|
1554
|
+
// Remove background (returns a Blob)
|
|
1555
|
+
const blob = await removeBackground(imageBuffer);
|
|
1556
|
+
|
|
1557
|
+
// Convert to buffer and save
|
|
1558
|
+
const outputBuffer = Buffer.from(await blob.arrayBuffer());
|
|
1559
|
+
fs.writeFileSync(outputPath, outputBuffer);
|
|
1560
|
+
|
|
1561
|
+
console.log(`Background removed! Saved to ${outputPath}`);
|
|
1562
|
+
} catch (error) {
|
|
1563
|
+
console.error('Error:', error);
|
|
1564
|
+
}
|
|
1565
|
+
};
|