ilhamdev commited on
Commit
1337d2e
·
verified ·
1 Parent(s): bb4174a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +22 -0
index.js CHANGED
@@ -978,6 +978,28 @@ return res.json({message: "Success", code: 200, data:data})
978
  });
979
  }
980
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
981
  .get('/tt', async (req, res) => {
982
  try {
983
  const { url } = req.query;
 
978
  });
979
  }
980
  })
981
+ .get('/removebg', async (req, res) => {
982
+ try {
983
+ let {transparentBackground } = await import("transparent-background")
984
+ let {url} = req.query
985
+ const inputUrl = (await axios.get(url, {
986
+ responseType: 'arraybuffer' // Set response type ke 'arraybuffer' untuk mendapatkan buffer
987
+ })).data
988
+
989
+ const output = await transparentBackground(Buffer.from(inputUrl), "png", {
990
+ // uses a 1024x1024 model by default
991
+ // enabling fast uses a 384x384 model instead
992
+ fast: false,
993
+ });
994
+ res.set('Content-Type', 'application/octet-stream'); // Set content type untuk buffer
995
+ return res.send(output);
996
+ } catch (e) {
997
+ console.log(e);
998
+ return res.json({ message: "Internal Server Error",
999
+ code: 500
1000
+ })
1001
+ }
1002
+ })
1003
  .get('/tt', async (req, res) => {
1004
  try {
1005
  const { url } = req.query;