-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5870341
Showing
22 changed files
with
4,055 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Remove Background</title> | ||
<meta charset="UTF-8" /> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
|
||
<h1 style="color: #ff0023;text-align:center;" class="my-2">Remove Image Background</h1> | ||
|
||
<div class="my-4 mb-3" style="width:60%; margin:0px auto;"> | ||
<input class="form-control" id="formFile" type="file" /> | ||
</div> | ||
|
||
<br> | ||
|
||
<table id="myTable" hidden="true" class="table table-warning table-striped text-center"> | ||
<tr> | ||
<td><div style="margin: auto; max-width: 800px;" id="result1"></div></td> | ||
<td><div id="convert"></div> </td> | ||
<td><div style="margin: auto; max-width: 800px;" id="result"></div></td> | ||
</tr> | ||
</table> | ||
<br> | ||
|
||
<div style="text-align:center" ><button hidden="true" onClick="window.location.reload();" type="button" class="btn btn-danger" id="clearBtn">Clear Window</button> <button hidden="true" type="button" class="btn btn-success" id="downBtn"></button> | ||
|
||
</div> | ||
|
||
|
||
<script type="module" src="index.js"></script> | ||
<script src="./node_modules/blueimp-load-image/js/load-image.all.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
document | ||
.querySelector("input[type=file]") | ||
.addEventListener("change", async function () { | ||
const resizedImage = await loadImage(this.files[0], { | ||
|
||
//resizing image using blue-load-image module | ||
|
||
maxWidth: 1500, | ||
maxHeight: 1500, | ||
canvas: true | ||
}); | ||
|
||
resizedImage.image.toBlob(async function (inputBlob) { | ||
const formData = new FormData(); | ||
|
||
//display table | ||
|
||
document.getElementById("myTable").removeAttribute("Hidden"); | ||
|
||
//display input image | ||
const inputImage = document.createElement("img"); | ||
document.querySelector("#result1").appendChild(inputImage); | ||
inputImage.style.width = "250px"; | ||
inputImage.style.height = "250px"; | ||
inputImage.src = URL.createObjectURL(inputBlob); | ||
|
||
//display loader | ||
|
||
const conImage = document.createElement("img"); | ||
document.querySelector("#convert").appendChild(conImage); | ||
conImage.style.width = "25%"; | ||
conImage.src = "spinner3.gif"; | ||
|
||
//api call | ||
formData.append("image_file", inputBlob); | ||
|
||
const response = await fetch("https://sdk.photoroom.com/v1/segment", { | ||
method: "POST", | ||
headers: { | ||
"x-api-key": "102279905dd5fd330cfa4d33c0ee13646946d683" | ||
}, | ||
body: formData | ||
}); | ||
|
||
|
||
//output image | ||
|
||
const outputBlob = await response.blob(); | ||
conImage.src = "arrow.png"; | ||
conImage.style.marginTop = "20%"; | ||
|
||
const outputImage = document.createElement("img"); | ||
document.querySelector("#result").appendChild(outputImage); | ||
outputImage.style.width = "250px"; | ||
outputImage.style.height = "250px"; | ||
outputImage.src = URL.createObjectURL(outputBlob); | ||
|
||
//download button | ||
|
||
const getImg = document.createElement("a"); | ||
const downBtn = document.querySelector("#downBtn"); | ||
downBtn.appendChild(getImg); | ||
downBtn.removeAttribute("Hidden"); | ||
getImg.href = URL.createObjectURL(outputBlob); | ||
getImg.style.textDecoration = "none"; | ||
getImg.style.color = "inherit"; | ||
getImg.download = "removed-bg-image"; | ||
getImg.innerText = "Download (PNG)"; | ||
|
||
//display clear button | ||
|
||
const clearBtn = document.querySelector("#clearBtn"); | ||
clearBtn.removeAttribute("Hidden"); | ||
|
||
|
||
|
||
|
||
}); | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.