एक ही HTTPS अनुरोध से अपने ऐप, शॉप या पाइपलाइन में बैकग्राउंड हटाएँ।
बेस URL: https://bgcut.net/api/v1 · अपनी कुंजी यहाँ प्राप्त करें: API कुंजियाँ.
प्रमाणीकरण
हर अनुरोध में X-Api-Key हेडर में आपकी API कुंजी होनी चाहिए। कुंजियाँ आपके खाते में बनाई और रद्द की जाती हैं; हर कुंजी को नाम दिया जा सकता है ताकि आप उन्हें प्रत्येक एप्लिकेशन के लिए अलग से बदल सकें।
// Never ship your API key in public front-end code – proxy through your server.
const input = document.querySelector('input[type=file]');
input.addEventListener('change', async () => {
const form = new FormData();
form.append('image_file', input.files[0]);
form.append('size', 'preview');
const res = await fetch('https://bgcut.net/api/v1/remove', { method: 'POST', headers: { 'X-Api-Key': 'bgc_YOUR_API_KEY' }, body: form });
const blob = await res.blob();
document.querySelector('img#out').src = URL.createObjectURL(blob);
});
// Java 11+ HttpClient, no external libraries
import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
public class BgCut {
public static void main(String[] a) throws Exception {
String key = "bgc_YOUR_API_KEY";
String boundary = "----bgcut" + System.nanoTime();
byte[] file = Files.readAllBytes(Path.of("photo.jpg"));
String head = "--" + boundary + "\r\nContent-Disposition: form-data; name=\"image_file\"; filename=\"photo.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n";
String tail = "\r\n--" + boundary + "\r\nContent-Disposition: form-data; name=\"size\"\r\n\r\nauto\r\n--" + boundary + "--\r\n";
byte[] body = concat(head.getBytes(), file, tail.getBytes());
HttpRequest req = HttpRequest.newBuilder(URI.create("https://bgcut.net/api/v1/remove"))
.header("X-Api-Key", key)
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.POST(HttpRequest.BodyPublishers.ofByteArray(body)).build();
HttpResponse<byte[]> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofByteArray());
if (res.statusCode() == 200) Files.write(Path.of("result.png"), res.body());
else System.out.println(new String(res.body()));
}
static byte[] concat(byte[]... parts) { int n = 0; for (byte[] p : parts) n += p.length; byte[] out = new byte[n]; int o = 0; for (byte[] p : parts) { System.arraycopy(p, 0, out, o, p.length); o += p.length; } return out; }
}
using System.Net.Http;
using System.Net.Http.Headers;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-Api-Key", "bgc_YOUR_API_KEY");
using var form = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(await File.ReadAllBytesAsync("photo.jpg"));
fileContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
form.Add(fileContent, "image_file", "photo.jpg");
form.Add(new StringContent("auto"), "size");
form.Add(new StringContent("png"), "format");
var res = await client.PostAsync("https://bgcut.net/api/v1/remove", form);
if (res.IsSuccessStatusCode)
await File.WriteAllBytesAsync("result.png", await res.Content.ReadAsByteArrayAsync());
else
Console.WriteLine(await res.Content.ReadAsStringAsync());
अपलोड करने के बजाय प्राप्त की जाने वाली इमेज का सार्वजनिक URL।
image_file_b64
string
Base64-एन्कोडेड इमेज (वैकल्पिक रूप से data: प्रीफ़िक्स के साथ)।
size
auto | preview | full
preview = अधिकतम 640 px (आपके मुफ़्त मासिक कोटे से, कोई क्रेडिट नहीं); full = मूल रिज़ॉल्यूशन (1 क्रेडिट); auto (डिफ़ॉल्ट) = क्रेडिट होने पर full, अन्यथा preview।
format
png | jpg | webp
आउटपुट फ़ॉर्मेट। png पारदर्शिता बनाए रखता है; jpg को bg_color (डिफ़ॉल्ट सफ़ेद) पर फ़्लैट किया जाता है।
model
fast | hq | portrait
fast (डिफ़ॉल्ट, ~1 s), hq (उच्च गुणवत्ता, धीमा), portrait (लोगों के लिए अनुकूलित)।
bg_color
string
बैकग्राउंड के लिए हेक्स रंग, जैसे #ffffff। पारदर्शी के लिए इसे छोड़ दें।
bg_blur
number
मूल बैकग्राउंड रखें, लेकिन उसे पिक्सेल में दी गई इस त्रिज्या (1–200) से धुंधला करें, जैसे पोर्ट्रेट-मोड लुक के लिए 25। यह bg_color को ओवरराइड करता है।
crop
boolean
आउटपुट को विषय के बाउंडिंग बॉक्स तक क्रॉप करें।
crop_margin
integer
क्रॉप करते समय विषय के चारों ओर पिक्सेल में अतिरिक्त मार्जिन (0–200)।
roi
string
x,y,w,h भिन्नों (0–1) के रूप में रुचि का क्षेत्र। AI केवल इस आयत के अंदर देखता है; इसके बाहर का सब कुछ पारदर्शी हो जाता है।
feather
number
किनारों को इतने पिक्सेल की त्रिज्या से नरम करें (0–5)।
quality
integer
JPG/WebP गुणवत्ता 50–100 (डिफ़ॉल्ट 92)।
response
binary | json
binary (डिफ़ॉल्ट) इमेज लौटाता है; json मेटाडेटा के साथ base64 इमेज लौटाता है।
रिस्पॉन्स
सफल अनुरोध इमेज बाइट्स और इन हेडर के साथ HTTP 200 लौटाते हैं:
HTTP/1.1 200 OK
Content-Type: image/png
X-Credits-Charged: 1
X-Credits-Remaining: 149
X-Free-Remaining: 5
X-Width: 3000
X-Height: 2000
X-Image-Id: 1f3a…
X-Type: hd