I Have A Website Made With Wordpress
I Have A Website Made With Wordpress
document.addEventListener('DOMContentLoaded', function () {
const form = document.getElementById('background-remover-form');
const resultDiv = document.getElementById('result');
const loader = document.getElementById('loader');
fetch(ajax_object.ajax_url + '?action=remove_background', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
// Hide the loader
loader.style.display = 'none';
if (data.error) {
resultDiv.innerHTML = `<p style="color:red;">${data.error}</p>`;
} else {
resultDiv.innerHTML = `
<img src="data:image/png;base64,${data.image}" alt="Processed
Image" style="max-width:100%;"/>
<a href="${data.download_url}" download="no-bg.png"
style="display:block; margin-top:10px;">Download Image</a>
`;
}
})
.catch(error => {
// Hide the loader
loader.style.display = 'none';
resultDiv.innerHTML = `<p style="color:red;">An error occurred: $
{error.message}</p>`;
});
});
});
function remove_background_function() {
// Check if a file is uploaded
if (!empty($_FILES['image_upload']['name'])) {
$api_key = 'Ruec5pxTkKmsv3979gFaNbt8'; // Your Remove.bg API Key
$file = $_FILES['image_upload'];
$data = [
'image_file' => new CURLFile($file['tmp_name']),
'size' => 'auto'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $api_key,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Background Remover</title>
<style>
/* Global Styles */
body {
font-family: "Roboto", Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #eef2f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
/* Card Container */
#background-remover {
background-color: ;
border-radius: 16px;
box-shadow: 0 0 100px rgba(136, 253, 239, 0.6);
padding: 25px;
max-width: 400px;
width: 90%;
text-align: center;
background: #ffffff;
}
#contact-us-button {
background-color: #3498db;
color: #fff;
font-size: 1rem;
border: none;
border-radius: 8px;
padding: 10px 20px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 10px;
}
#condition-contact {
display: flex;
text-align: center;
font-size: 10px;
align-items: center;
justify-content: center;
}
#contact-us-button:hover {
background-color: red;
}
/* Form Styles */
#background-remover-form {
margin-bottom: 20px;
}
label {
font-size: 1rem;
font-weight: 600;
display: block;
margin-bottom: 10px;
color: #0c0d0e;
}
input[type="file"] {
border: 1px solid #09dfdf;
border-radius: 8px;
padding: 10px;
width: 100%;
box-sizing: border-box;
transition: border-color 0.3s ease;
background-color: #c4c7c7;
}
input[type="file"]:focus {
border-color: #028ce7;
outline: none;
}
form button {
background: linear-gradient(135deg, #03df0e, #007bff);
color: #ffffff;
font-size: 1rem;
border: none;
border-radius: 8px;
padding: 12px 20px;
cursor: pointer;
transition: background 0.3s ease, transform 0.2s ease;
margin-top: 15px;
}
form button:hover {
background: linear-gradient(135deg, #007bff, #4cafef);
transform: translateY(-2px);
}
form button:active {
transform: translateY(0);
}
/* Loader Styles */
.spinner {
border: 6px solid #f3f3f3; /* Light grey */
border-top: 6px solid #4cafef; /* Blue */
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: auto;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#loader {
display: none;
margin-top: 20px;
}
#loader p {
font-size: 0.9rem;
margin-top: 10px;
color: #555;
}
/* Result Section */
#result img {
max-width: 100%;
height: auto;
margin-top: 20px;
border-radius: 12px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
#result a {
display: inline-block;
margin-top: 10px;
padding: 12px 25px;
background: linear-gradient(135deg, #28a745, #2ecc71);
color: #fff;
text-decoration: none;
border-radius: 8px;
transition: background 0.3s ease, transform 0.2s ease;
}
#result a:hover {
background: linear-gradient(135deg, #2ecc71, #28a745);
transform: translateY(-2px);
}
</style>
</head>
<body>
<div id="background-remover">
<form id="background-remover-form" enctype="multipart/form-data">
<label for="image_upload">Upload an Image:</label>
<input
type="file"
id="image_upload"
name="image_upload"
accept="image/*"
required
/>
<button type="submit">Remove Background</button>
</form>
<div class="condition-contact">
<h6 class="condition" style="text-align: center">
To download the output photo you need to click on the contact us button.
</h6>
</div>
</div>
</body>
</html>