Noņemiet fonus savās lietotnēs, veikalos vai darbplūsmās ar vienu HTTPS pieprasījumu.
Bāzes URL: https://bgcut.net/api/v1 · Atslēgu saņemiet sadaļā API atslēgas.
Autentifikācija
Katrā pieprasījumā galvenē X-Api-Key jānorāda jūsu API atslēga. Atslēgas var izveidot un atsaukt savā kontā. Katrai atslēgai var piešķirt nosaukumu, lai tās varētu nomainīt katrai lietotnei atsevišķi.
// 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());
Publisks attēla URL, no kura attēlu ielādēt augšupielādes vietā.
image_file_b64
string
Base64 kodēts attēls (pēc izvēles ar data: prefiksu).
size
auto | preview | full
preview = līdz 640 px (izmanto bezmaksas mēneša kvotu, bez kredītiem); full = oriģinālā izšķirtspēja (1 kredīts); auto (noklusējums) = full, ja jums ir kredīti, pretējā gadījumā preview.
format
png | jpg | webp
Izvades formāts. png saglabā caurspīdīgumu; jpg tiek saplacināts uz bg_color fona (pēc noklusējuma balts).
model
fast | hq | portrait
lite (noklusējums, ~6 s, labākais līdzsvars), fast (~0,5 s, priekšskatījuma kvalitāte), hq (~15 s, maksimālā kvalitāte), portrait (~0,3 s, tikai cilvēkiem).
bg_color
string
Fona krāsa heksadecimālā formātā, piem., #ffffff. Izlaidiet, lai fons būtu caurspīdīgs.
bg_blur
number
Saglabā oriģinālo fonu, bet izpludina to ar norādīto rādiusu pikseļos (1–200), piem., 25 portreta režīma efektam. Aizstāj bg_color.
crop
boolean
Apgriež izvadi līdz objekta robežām.
crop_margin
integer
Papildu atstarpe pikseļos ap objektu apgriešanas laikā (0–200).
roi
string
Interešu apgabals kā daļas x,y,w,h (0–1). AI analizē tikai šo taisnstūri; viss ārpus tā kļūst caurspīdīgs.
feather
number
Mīkstina malas ar norādīto rādiusu pikseļos (0–5).
quality
integer
JPG/WebP kvalitāte 50–100 (noklusējums 92).
response
binary | json
binary (noklusējums) atgriež attēlu; json atgriež metadatus un attēlu base64 formātā.
Atbildes
Veiksmīgi pieprasījumi atgriež HTTP 200 ar attēla baitiem un šīm galvenēm:
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