Created
December 23, 2025 10:40
-
-
Save manzxy/ec5c9246318b35de9cf49a2e0067c2cd to your computer and use it in GitHub Desktop.
Uploaded via YogiriMD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| • Fitur: Removebg | |
| • Sumber: https://whatsapp.com/channel/0029VbBS8ys0G0XnmJFRiV2v | |
| • Sumber Scrape: https://whatsapp.com/channel/0029VbAc3Y71HspoyMVys03X/552 | |
| **/ | |
| import axios from "axios" | |
| import fs from "fs" | |
| import FormData from "form-data" | |
| import path from "path" | |
| async function getToken() { | |
| const { data } = await axios.get( | |
| "https://removal.ai/wp-admin/admin-ajax.php?action=ajax_get_webtoken&security=1cf5632768" | |
| ) | |
| return data.data.webtoken | |
| } | |
| async function removeBg(filePath) { | |
| const form = new FormData() | |
| form.append("image_file", fs.createReadStream(filePath)) | |
| const token = await getToken() | |
| const { data } = await axios.post( | |
| "https://api.removal.ai/3.0/remove", | |
| form, | |
| { | |
| headers: { | |
| "user-agent": | |
| "Mozilla/5.0 (Linux; Android 6.0) AppleWebKit/537.36 Chrome/142 Mobile", | |
| "sec-ch-ua": | |
| '"Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"', | |
| origin: "https://removal.ai", | |
| accept: "*/*", | |
| "web-token": token, | |
| ...form.getHeaders() | |
| } | |
| } | |
| ) | |
| return { | |
| url: data.url, | |
| low_resolusi: data.low_resolution || null, | |
| demo: data.preview_demo || null, | |
| extra: data.extra || null, | |
| original: data.original | |
| } | |
| } | |
| let handler = async (m, { conn }) => { | |
| try { | |
| const q = m.quoted || m | |
| const mime = (q.msg || q).mimetype || "" | |
| if (!/image\/(png|jpe?g)/i.test(mime)) | |
| return m.reply("🖼️ Reply / kirim gambar dengan caption *.removebg*") | |
| await m.reply("✂️ Menghapus background...") | |
| // download image | |
| const buffer = await q.download() | |
| if (!buffer) return m.reply("❌ Gagal mengambil gambar") | |
| const tmp = path.join( | |
| "/tmp", | |
| `removebg_${Date.now()}.png` | |
| ) | |
| fs.writeFileSync(tmp, buffer) | |
| const res = await removeBg(tmp) | |
| fs.unlinkSync(tmp) | |
| // kirim hasil | |
| await conn.sendMessage( | |
| m.chat, | |
| { | |
| image: { url: res.url }, | |
| caption: | |
| "✅ *Background berhasil dihapus*\n\n" + | |
| (res.low_resolusi | |
| ? "🔗 Low Res: " + res.low_resolusi | |
| : "") | |
| }, | |
| { quoted: m } | |
| ) | |
| } catch (e) { | |
| console.error(e) | |
| m.reply("❌ Gagal remove background") | |
| } | |
| } | |
| handler.help = ["removebg"] | |
| handler.tags = ["tools", "ai"] | |
| handler.command = ["removebg", "nobg"] | |
| export default handler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment