-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
47 lines (40 loc) · 1.26 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
<html>
<head>
<title>WebP decoding</title>
<script type="text/javascript">
if ('serviceWorker' in navigator) {
void async function install() {
await navigator.serviceWorker.register('sw.js');
const registration = await navigator.serviceWorker.ready;
registration.active.onstatechange = (state) => {
for (const img of document.querySelectorAll('img')) {
if (img.src.endsWith('.webp')) {
img.src = img.src; // reload.
}
}
}
}();
}
</script>
<script type="module">
import { fetchWebPDecoder } from './webp-decoder.js';
async function loadImage(filename) {
const response = await fetch(filename);
const buffer = await response.arrayBuffer();
const WebPDecoder = await fetchWebPDecoder();
const decoder = new WebPDecoder(buffer);
const data = await decoder.decodeToBMP();
var blob = new Blob([data], {type : 'image/bmp'});
const img = document.createElement('img');
img.src = URL.createObjectURL(blob);
document.body.appendChild(img);
}
loadImage('test4.webp');
</script>
</head>
<body>
<img src='test1.webp'></img>
<img src='test2.webp'></img>
<img src='test3.webp'></img>
</body>
</html>