-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
42 lines (40 loc) · 1.1 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<script module type="module">
import { pngValidator } from "https://unpkg.com/[email protected]/index.js";
const input = document.querySelector("#file-input");
input.addEventListener("change", readPng);
function readPng() {
const file = input.files?.[0];
if (!file) {
console.log("no file");
return;
}
const reader = new FileReader();
reader.onload = function (e) {
const file = e.target?.result;
if (!file) {
console.log("no file in onload");
return;
}
if (typeof file === "string") {
console.log("file is string");
return;
}
const png = new Uint8Array(file);
try {
pngValidator(png);
console.log("file is valid");
} catch (e) {
console.log("file is invalid", e);
}
};
reader.readAsArrayBuffer(file);
}
</script>
</head>
<body>
<input id="file-input" type="file" accept=".png" />
</body>
</html>