-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
46 lines (44 loc) · 1.63 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
45
46
<html>
<input type="file" id="input" onchange="reader.readAsDataURL(this.files[0])">
<h1>grafi.js brightness sample</h1>
<h2>original</h2>
<img id="original">
<h2>processed</h2>
<div id="slider" hidden>
<input id="level" type="range" min="-255" max="255" value="0"/>
<label id="label">0</label>
</div>
<canvas id="canvas" hidden></canvas>
<canvas id="output"></canvas>
<script src="grafi-brightness.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.brightness(canvasCtx.getImageData(0, 0, original.width, original.height), {level: 0})
outputCtx.putImageData(newImage, 0, 0)
level.oninput = function() {
var l = this.value
var updatedImage = grafi.brightness(canvasCtx.getImageData(0, 0, original.width, original.height), {level: parseInt(l)})
outputCtx.putImageData(updatedImage, 0, 0)
label.innerText = l
}
}
</script>
</hmtl>