aijavascript12010
BRIA RMBG 1.4 - AI Remove Background (URL & File Lokal, No API, Non-Cloudflare)
Scraper AI Background Remover gratis berbasis model BRIA RMBG 1.4 tanpa perlu API key dan bebas dari Cloudflare / Turnstile captcha. Mendukung input URL gambar publik, file lokal di server/disk, Buffer biner (Bot WA), maupun Base64.
Vamz Spectre5 Okt 2026157 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/bria-rmbg-remover" -o bria-rmbg-remover.js
# 2. Jalankan script
node bria-rmbg-remover.js
Dependencies npm yang Dibutuhkan:
npm install @gradio/clientPanduan Penggunaan:
// Instalasi dependensi:
npm install @gradio/client
// ==========================================
// 1. PENGGUNAAN TERMINAL / CLI:
// ==========================================
// A. Pakai URL gambar:
node bria-rmbg-remover.js https://example.com/foto.jpg --out hasil.png
// B. Pakai File Lokal:
node bria-rmbg-remover.js ./foto_saya.jpg --out nobg.png
// ==========================================
// 2. PENGGUNAAN MODUL (BOT WA / NODE.JS):
// ==========================================
const { removeBackground } = require(./bria-rmbg-remover);
async function main() {
// Contoh A: Dari URL Gambar
const res1 = await removeBackground("https://example.com/foto.jpg", {
outPath: "hasil_url.png" // simpan otomatis
});
console.log("URL Sukses:", res1.url, res1.size);
// Contoh B: Dari File Lokal di server/komputer
const res2 = await removeBackground("./gambar_lokal.jpg", {
outPath: "hasil_lokal.png"
});
console.log("Lokal Sukses:", res2.size);
// Contoh C: Dari Buffer (misal bot WhatsApp Baileys)
// const mediaBuffer = await downloadMediaMessage(m);
// const res3 = await removeBackground(mediaBuffer);
// await sock.sendMessage(m.chat, { image: res3.buffer, caption: "Background removed!" });
}
main();bria-rmbg-remover.js(157 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* ====================================================================
* BRIA RMBG 1.4 - AI Background Remover Scraper (Free & Non-Cloudflare)
* Author: Vamz Spectre
* Mendukung: URL Gambar, Path File Lokal, Buffer Node.js, & Base64
* Tanpa API Key & Bebas Cloudflare / Turnstile Captcha
* ====================================================================
*/
const fs = require("fs");
const path = require("path");
/**
* Menghapus background dari gambar secara otomatis
* @param {string | Buffer} input - Bisa berupa:
* 1. URL Gambar publik ("https://example.com/foto.jpg")
* 2. Path File Lokal ("./foto.jpg" atau "/root/foto.png")
* 3. Buffer gambar (Buffer dari bot WhatsApp / upload)
* 4. Base64 string ("data:image/png;base64,..." atau raw base64)
* @param {object} [options] - Opsi konfigurasi
* @param {string} [options.outPath] - Path file tujuan jika ingin langsung disimpan ke disk
* @returns {Promise<{ success: boolean, buffer: Buffer, url: string, size: number, mimeType: string }>}
*/
async function removeBackground(input, options = {}) {
// Menggunakan @gradio/client untuk koneksi websocket/SSE mulus ke model BRIA RMBG 1.4
const { Client } = await import("@gradio/client");
// Endpoint publik tanpa autentikasi / non-Cloudflare
const client = await Client.connect("briaai/BRIA-RMBG-1.4");
let blob;
// 1. Tipe Input: String (Bisa URL, Base64, atau Path File Lokal)
if (typeof input === "string") {
const trimmed = input.trim();
// A. URL Gambar (HTTP / HTTPS)
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
const res = await fetch(trimmed);
if (!res.ok) {
throw new Error(`Gagal mengunduh gambar dari URL (${res.status} ${res.statusText})`);
}
blob = await res.blob();
}
// B. Base64 String (Data URI atau raw Base64)
else if (trimmed.startsWith("data:image/") || (trimmed.length > 100 && /^[A-Za-z0-9+/=\s]+$/.test(trimmed))) {
const b64Data = trimmed.includes(",") ? trimmed.split(",")[1] : trimmed;
const buf = Buffer.from(b64Data, "base64");
blob = new Blob([new Uint8Array(buf)], { type: "image/png" });
}
// C. Path File Lokal (Relatif maupun Absolut)
else {
const resolvedPath = path.resolve(trimmed);
if (!fs.existsSync(resolvedPath)) {
throw new Error(`File lokal tidak ditemukan di: ${trimmed}`);
}
const fileBuffer = fs.readFileSync(resolvedPath);
// Tentukan mime type sederhana berdasarkan ekstensi
const ext = path.extname(resolvedPath).toLowerCase();
const mimeType = ext === ".jpg" || ext === ".jpeg" ? "image/jpeg" : (ext === ".webp" ? "image/webp" : "image/png");
blob = new Blob([new Uint8Array(fileBuffer)], { type: mimeType });
}
}
// 2. Tipe Input: Binary Buffer (Misal: hasil downloadMediaMessage bot WhatsApp)
else if (Buffer.isBuffer(input)) {
blob = new Blob([new Uint8Array(input)], { type: "image/png" });
}
// 3. Tipe Input: Blob
else if (input instanceof Blob) {
blob = input;
}
else {
throw new Error("Format input tidak didukung. Harap berikan URL gambar, path file lokal, Buffer, atau Base64.");
}
// Kirim gambar ke AI untuk proses penghapusan background
const result = await client.predict("/run", { image: blob });
// Index 1 pada kembalian data BRIA RMBG 1.4 adalah file PNG dengan background transparan
const fileData = result.data?.[1];
if (!fileData || !fileData.url) {
throw new Error("Gagal menerima hasil gambar transparan dari server AI.");
}
// Unduh buffer biner hasil gambar transparan
const imgRes = await fetch(fileData.url);
if (!imgRes.ok) {
throw new Error(`Gagal mengunduh gambar hasil: ${imgRes.statusText}`);
}
const arrayBuf = await imgRes.arrayBuffer();
const buffer = Buffer.from(arrayBuf);
// Jika outPath diisi, simpan langsung ke penyimpanan lokal
if (options.outPath) {
const targetDir = path.dirname(path.resolve(options.outPath));
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
fs.writeFileSync(options.outPath, buffer);
}
return {
success: true,
buffer,
url: fileData.url,
size: buffer.length,
mimeType: "image/png"
};
}
if (typeof module !== "undefined" && module.exports) {
module.exports = {
removeBackground
};
}
// ====================================================================
// CLI Handler: Eksekusi Langsung dari Terminal
// ====================================================================
if (require.main === module) {
const args = process.argv.slice(2);
const target = args.find(a => !a.startsWith("--"));
if (!target) {
console.log("Penggunaan CLI:");
console.log(" node rmbg.js <url_atau_path_file> [--out hasil.png]");
console.log("");
console.log("Contoh:");
console.log(" 1. Menggunakan URL gambar:");
console.log(" node rmbg.js https://example.com/foto.jpg --out hasil.png");
console.log("");
console.log(" 2. Menggunakan File Lokal:");
console.log(" node rmbg.js ./foto_saya.jpg --out nobg.png");
process.exit(1);
}
const outIndex = args.indexOf("--out");
const outFile = (outIndex !== -1 && args[outIndex + 1]) ? args[outIndex + 1] : "output_nobg.png";
console.log(`[RMBG AI] Memproses gambar (${target.startsWith("http") ? "URL" : "File Lokal"})...`);
const startTime = Date.now();
removeBackground(target, { outPath: outFile })
.then(res => {
const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);
console.log(`[RMBG AI] Sukses dalam ${elapsed} detik!`);
console.log(` - File Disimpan : ${outFile}`);
console.log(` - Ukuran Output : ${res.size} bytes`);
console.log(` - Direct URL : ${res.url}`);
})
.catch(err => {
console.error(`[RMBG AI] Gagal:`, err.message);
process.exit(1);
});
}