-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.html
79 lines (64 loc) · 2.37 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<title>as-dithered-image.js Test Page</title>
</head>
<body>
<script src="as-dithered-image.js"></script>
<p>A short, hacky demo page - used only for internal testing. See the blog post for a better one.</p>
<as-dithered-image id="picture" src="Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg"></as-dithered-image>
<div>devicePixelRatio = <span id=dpr>0</span></p>
<select id="crunchselect">
<option value="auto">Automatic</option>
<option value="pixel">Pixel</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input id="cutoff" type="range" min="0.0" max="1.0" step="0.05" value="any" />
<input id="choosefile" type="file" />
Drag and drop works as well
</div>
</body>
<script>
function displayFromFile(file) {
if (!file.type.startsWith("image/")) {
return
}
const reader = new FileReader();
reader.onload = (e) => {
document.getElementById("picture").setAttribute("src", e.target.result)
}
reader.readAsDataURL(file)
}
document.getElementById("dpr").innerText = window.devicePixelRatio
let select = document.getElementById("crunchselect")
select.addEventListener("change", e => {
console.log("Crunch = ", e.target.value)
document.getElementById("picture").setAttribute("crunch", e.target.value)
})
document.getElementById("cutoff").addEventListener("change", e => {
console.log("Value = ", e.target.value)
document.getElementById("picture").setAttribute("cutoff", e.target.value)
})
document.getElementById("choosefile").addEventListener("change", e => {
const files = e.target.files
if (files.length == 0) {
return
}
displayFromFile(files[0])
}, false)
const pictureElement = document.getElementById("picture")
pictureElement.addEventListener("drop", e => {
e.preventDefault()
if (e.dataTransfer.files.length == 0) {
return
}
displayFromFile(e.dataTransfer.files[0])
})
pictureElement.addEventListener("dragover", e => {
e.preventDefault() // need this to disable the default
})
</script>
</html>