-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (50 loc) · 1.91 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let profilePic = document.getElementById("image");
let inputFile = document.getElementById("fileInput");
inputFile.onchange = function(){
profilePic.src = URL.createObjectURL(inputFile.files[0]);
};
{/* <div id="" style="height:41rem;">
<img id="image" src="/photos/done-code tick png.png" />
</div> */}
let imageURL;
function submitHandler() {
console.log("click");
const fileInput = document.getElementById("fileInput");
console.log(fileInput.files);
const image = fileInput.files[0];
// Multipart file
const formData = new FormData();
formData.append("image_file", image);
formData.append("size", "auto");
// const apiKey = "7kzU8R5gSQvqPxVg2wzSWWXd";
const apiKey = "ut55h2TNEYwaGBgesV6FJzt6";
fetch("https://api.remove.bg/v1.0/removebg", {
method: "POST",
headers: {
"X-Api-Key": apiKey,
},
body: formData,
})
.then(function (reponse) {
return reponse.blob();
})
.then(function (blob) {
console.log(blob);
const url = URL.createObjectURL(blob);
imageURL = url;
const img = document.createElement("img");
img.src = url;
const ff = document.getElementById("imageRmv")
// document.body.appendChild(img);
ff.appendChild(img);
})
.catch();
}
function downloadFile() {
var a = document.createElement("a"); //<a></a>
a.href = imageURL;
a.download = "naciasv.png";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}