-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
44 lines (43 loc) · 1.62 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
43
44
<html>
<input type="file" id="input" onchange="reader.readAsDataURL(this.files[0])">
<h1>original</h1>
<img id="original">
<h1>processed</h1>
<div id="slider" hidden>
<input id="level" type="range" min="10" max="190" value="100"/>
<label id="label">1</label>
</div>
<canvas id="canvas" hidden></canvas>
<canvas id="output"></canvas>
<script src="grafi-contrast.js"></script>
<script>
var slider = document.getElementById('slider')
var level = document.getElementById('level')
var label = document.getElementById('label')
var original = document.getElementById('original')
var canvas = document.getElementById('canvas')
var output = document.getElementById('output')
var canvasCtx = canvas.getContext('2d')
var outputCtx = output.getContext('2d')
var reader = new FileReader()
reader.onload = function() {
original.src = reader.result
}
original.onload = function () {
slider.hidden = false
canvas.width = original.width
canvas.height = original.height
output.width = original.width
output.height = original.height
canvasCtx.drawImage(original, 0, 0)
newImage = grafi.contrast(canvasCtx.getImageData(0, 0, original.width, original.height), {level: 1})
outputCtx.putImageData(newImage, 0, 0)
level.oninput = function() {
var l = this.value < 100 ? this.value / 100 : (this.value - 90) / 10
var updatedImage = grafi.contrast(canvasCtx.getImageData(0, 0, original.width, original.height), {level: l})
outputCtx.putImageData(updatedImage, 0, 0)
label.innerText = l
}
}
</script>
</hmtl>