Visão Geral
API de Remoção de Fundo com JavaScript
JavaScript facilita a integração de uploads de imagens e processamento por IA em aplicações web modernas.
STEP 1
<input type="file"
id="imageInput">
<button onclick="removeBg()">
Remove Background
</button>
<div id="result"></div>
STEP 2
Exemplo com Fetch API
Envie uma imagem usando FormData e receba uma imagem PNG transparente.
async function removeBg(){
const fileInput =
document.getElementById("imageInput");
const result =
document.getElementById("result");
if(!fileInput.files.length){
alert("Select image first");
return;
}
const formData = new FormData();
formData.append(
"file",
fileInput.files[0]
);
result.innerHTML =
"Processing...";
try{
const response = await fetch(
"/ajax/remove-bg.php",
{
method:"POST",
body:formData
}
);
if(!response.ok){
throw new Error();
}
const blob =
await response.blob();
const url =
URL.createObjectURL(blob);
result.innerHTML = `
<img src="${url}"
style="max-width:100%;">
<br><br>
<a href="${url}"
download="no-bg.png">
Download PNG
</a>
`;
}catch{
result.innerHTML =
"Something went wrong";
}
}
FEATURES
Recursos Recomendados
SECURITY
Importante
ERRORS
Error
Description
401
413
429
500
Continuar para Python
Aprenda a automatizar a remoção de fundo usando Python e a API ByByBG.