@xuda.io/account_module 1.2.242 → 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.
Files changed (2) hide show
  1. package/index.mjs +20 -1
  2. package/package.json +2 -1
package/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import path from 'path';
2
2
  import _ from 'lodash';
3
- import { createRequire } from 'module';
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
+ };
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.242",
3
+ "version": "1.2.244",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {
7
+ "@imgly/background-removal-node": "^1.4.5",
7
8
  "lodash": "^4.17.21",
8
9
  "validator": "^13.1.1"
9
10
  },