-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab_02_1.html
More file actions
37 lines (31 loc) · 1.6 KB
/
lab_02_1.html
File metadata and controls
37 lines (31 loc) · 1.6 KB
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
<html>
<body>
<canvas width="500" , height="281" , id="layer_1"> </canvas>
<canvas width="500" , height="281" , id="layer_2"> </canvas>
<script>
var canvas = document.getElementById("layer_1");
var ctx = canvas.getContext("2d");
var canvas2 = document.getElementById("layer_2");
var ctx2 = canvas2.getContext("2d");
let img = new Image();
img.crossOrigin = "anonymus";
img.src = "https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg"; //Jerry meme.jpg
let _average=0;
let img_data = new ImageData(1,1);
img.onload = function () {
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
img_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
console.log(img_data);
for (var index = 0; index < img_data.data.length; index += 4)
{
_average = (img_data.data[index] + img_data.data[index+1] + img_data.data[index+2])/3;
img_data.data[index] = _average;
img_data.data[index + 1] = _average;
img_data.data[index + 2] = _average;
img_data.data[index + 3] = 255;
}
ctx2.putImageData(img_data, 0, 0, 0, 0, canvas2.width, canvas2.height);
}
</script>
</body>
</html>