-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdemo.html
57 lines (54 loc) · 2.13 KB
/
demo.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
<!DOCTYPE html>
<html>
<head> </head>
<body>
<div id="imgContainer"></div>
<script src="blurhash_pure_js_port.min.js"></script>
<script>
const imgContainer = document.getElementById("imgContainer");
const img = new Image();
img.crossOrigin = "Anonymous";
img.onload = () => {
imgContainer.appendChild(img);
const imgData = blurhash.getImageData(img);
blurhash
.encodePromise(imgData, img.width, img.height, 4, 4)
.then(hash => {
return blurhash.decodePromise(
hash,
img.width,
img.height
);
})
.then(blurhashImgData => {
// as canvas element
const canvas = blurhash.drawImageDataOnNewCanvas(
blurhashImgData,
img.width,
img.height
);
document.body.appendChild(canvas);
// as image object with onload callback
const imgObject = blurhash.getImageDataAsImage(
blurhashImgData,
img.width,
img.height,
(event, imgObject) => {
document.body.appendChild(imgObject);
}
);
// as image object with promise
return blurhash.getImageDataAsImageWithOnloadPromise(
blurhashImgData,
img.width,
img.height
);
})
.then(imgObject => {
document.body.appendChild(imgObject);
});
};
img.src = "https://placecats.com/louie/400/400";
</script>
</body>
</html>