-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (38 loc) · 1.52 KB
/
Copy pathscript.js
File metadata and controls
52 lines (38 loc) · 1.52 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
let topTextInput,bottomTextInput,imageInput,generateBtn, canvas,ctx, fontSize, fontColor;
function generateMeme(img, topText,bottomText, fontSize, fontColor){
canvas.width = img.width;
canvas.height = img.height;
ctx.clearRect(0,0,canvas.width, canvas.height);
ctx.drawImage(img,0,0,img.width,img.height,0,0,canvas.width,canvas.height);
ctx.font = fontSize + 'px Segoe UI';
ctx.fillStyle = fontColor;
ctx.moveTo(10, 20);
ctx.textBaseline = "top";
ctx.fillText(topText, 50, 50);
ctx.moveTo(10, canvas.height - 20);
ctx.textBaseline = "bottom";
ctx.fillText(bottomText, 50, canvas.height-30);
}
function init(){
topTextInput = document.getElementById('topTextInput');
bottomTextInput = document.getElementById('bottomTextInput');
fontSize = document.getElementById('fontSize');
imageInput = document.getElementById('image-input');
generateBtn = document.getElementById('btn')
canvas = document.getElementById('canvas');
fontColor = document.getElementById("fontColor");
ctx = canvas.getContext('2d');
canvas.width = canvas.height = 0;
generateBtn.addEventListener('click', function(){
let reader = new FileReader();
reader.addEventListener("load", function () {
let img = new Image;
img.src = reader.result;
img.addEventListener("load", function() {
generateMeme(img, topTextInput.value, bottomTextInput.value, fontSize.value, fontColor.value)
});
}, false);
reader.readAsDataURL(imageInput.files[0]);
});
}
init();