Spaces:
Runtime error
Runtime error
File size: 4,559 Bytes
e572519 |
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Create 3D Icon</title>
<style>
* {
position: relative;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
#app {
height: 100%;
width: 100%;
overflow-y: auto;
}
#container {
display: flex;
flex-direction: column;
align-items: center;
}
#container > div {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
#in {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1rem;
}
#out {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1rem;
}
img {
width: 100%;
}
</style>
</head>
<body>
<div id="app">
<div id="container">
<div>
<h1>Create 3D Icon</h1>
</div>
<div>
<div id="in">
<input type="file" id="file" accept="image/svg+xml" />
<p id="status">Select an SVG file to create a 3D icon</p>
</div>
<div id="out">
<img id="img" />
</div>
</div>
</div>
</div>
<script>
const input = document.querySelector("#file");
const img = document.querySelector("#img");
const status = document.querySelector("#status");
let running = false;
async function run() {
if (running) {
alert("Still running");
return;
}
running = true;
input.disabled = true;
status.innerText = "Creating icon ...";
try {
const files = input.files;
if (files.length === 0) {
throw new Error("No file selected");
}
const file = files[0];
const reader = new FileReader();
reader.readAsText(file);
const svg = await new Promise((resolve, reject) => {
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
});
const res = await fetch("/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
svg,
size: 1024,
distance: 0.8,
light_x: 0.3,
light_strength: 3,
rotate_x: 10,
rotate_z: 10,
}),
});
if (!res.ok) {
throw new Error("Failed to create icon");
}
const data = await res.blob();
const url = URL.createObjectURL(data);
img.src = url;
status.innerText = "Done!";
} catch (err) {
alert(err.message);
status.innerText = "Error! " + err.message;
} finally {
running = false;
input.disabled = false;
}
}
input.addEventListener("change", run);
</script>
</body>
</html>
|