Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions Remove bg
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!DOCTYPE html>
<html lang="hi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Magic BG Remover</title>
<style>
body { background: #000; color: #fff; font-family: sans-serif; text-align: center; padding: 20px; margin: 0; }
.container { max-width: 450px; margin: auto; background: #111; padding: 20px; border-radius: 20px; border: 1px solid #333; }
.upload-area { border: 2px dashed #f39c12; border-radius: 15px; padding: 30px; cursor: pointer; margin-bottom: 20px; position: relative; }
#preview-img { width: 100%; border-radius: 10px; display: none; }
.btn { background: #f39c12; color: #000; width: 100%; padding: 15px; border: none; border-radius: 10px; font-weight: bold; font-size: 16px; cursor: pointer; }
.btn:disabled { background: #555; cursor: not-allowed; }
.loader { display: none; color: #f39c12; margin: 15px; font-weight: bold; }
#downloadBtn { display: none; margin-top: 15px; background: transparent; border: 2px solid #f39c12; color: #f39c12; }
</style>
</head>
<body>

<div class="container">
<h2 style="color: #f39c12;">AI Photo BG Remover</h2>

<div class="upload-area" onclick="document.getElementById('imageInput').click()">
<p id="hint">Photo Select Karein</p>
<input type="file" id="imageInput" accept="image/*" hidden>
<img id="preview-img">
</div>

<button class="btn" id="actionBtn" onclick="removeBackground()">Background Hatayein</button>

<div class="loader" id="loader">AI is Working... 💫</div>

<button class="btn" id="downloadBtn">Download PNG</button>
</div>

<script>
const imageInput = document.getElementById('imageInput');
const previewImg = document.getElementById('preview-img');
const actionBtn = document.getElementById('actionBtn');
const loader = document.getElementById('loader');
const downloadBtn = document.getElementById('downloadBtn');

// Photo select hone par preview dikhayein
imageInput.onchange = (e) => {
const file = e.target.files[0];
if (file) {
previewImg.src = URL.createObjectURL(file);
previewImg.style.display = 'block';
document.getElementById('hint').style.display = 'none';
downloadBtn.style.display = 'none';
}
};

// Main Function (Aapka API Code yahan converted hai)
async function removeBackground() {
const file = imageInput.files[0];
if (!file) return alert("Pehle ek photo select karein!");

loader.style.display = 'block';
actionBtn.disabled = true;

const formData = new FormData();
formData.append('image_file', file);
formData.append('size', 'auto');

// YAHAN APNI API KEY PASTE KAREIN
const apiKey = 'INSERT_YOUR_API_KEY_HERE';

try {
const response = await fetch('https://api.remove.bg/v1.0/removebg', {
method: 'POST',
headers: { 'X-Api-Key': apiKey },
body: formData
});

if (response.ok) {
const blob = await response.blob();
const noBgUrl = URL.createObjectURL(blob);

// Result dikhayein
previewImg.src = noBgUrl;
downloadBtn.style.display = 'block';
downloadBtn.onclick = () => {
const link = document.createElement('a');
link.href = noBgUrl;
link.download = "processed_image.png";
link.click();
};
alert("Background successfully hat gaya!");
} else {
const errData = await response.json();
alert("Error: " + errData.errors[0].title);
}
} catch (error) {
alert("Internet Connection check karein!");
} finally {
loader.style.display = 'none';
actionBtn.disabled = false;
}
}
</script>

</body>
</html>