-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
86 lines (79 loc) · 2.72 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./output.css" />
<title>Unimage demo</title>
</head>
<body>
<div class="container flex flex-col items-center mx-auto p-4 md:p-8">
<div class="form w-full max-w-md mb-4">
<form id="upload-form" class="flex flex-col">
<input
type="file"
id="photo-input"
accept="image/*"
class="mb-2 px-3 py-2 border border-gray-300 rounded"
/>
<div class="flex-col mb-2">
<input
type="number"
id="width"
placeholder="Width"
class="px-3 mb-2 w-14 py-2 border border-gray-300 rounded mr-2 flex-1"
/>
<input
type="number"
id="height"
placeholder="Height"
class="px-3 py-2 border border-gray-300 rounded flex-1"
/>
</div>
<button
type="submit"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Process Photo
</button>
</form>
</div>
<div class="flex justify-center items-center w-full max-w-md mb-4">
<div class="border-indigo-50 border" id="result-container"></div>
</div>
<textarea
id="html-output"
rows="10"
class="w-full max-w-md resize-none p-2 border border-gray-300 rounded"
></textarea>
</div>
<script src="./dist/unimage.js"></script>
<script>
const form = document.getElementById("upload-form");
const photoInput = document.getElementById("photo-input");
const widthInput = document.getElementById("width");
const heightInput = document.getElementById("height");
const resultContainer = document.getElementById("result-container");
const htmlOutput = document.getElementById("html-output");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const file = photoInput.files[0];
if (!file) {
alert("Please select a photo first.");
return;
}
const fileUrl = URL.createObjectURL(file);
resultContainer.innerHTML = "Loading...";
htmlOutput.value = "";
Unimage.generatePixels(fileUrl, widthInput.value, heightInput.value)
.then((newContent) => {
resultContainer.innerHTML = newContent;
htmlOutput.value = newContent;
})
.catch((error) => {
console.error("Error generating pixels:", error);
});
});
</script>
</body>
</html>