-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (54 loc) · 1.81 KB
/
main.js
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
80
81
82
83
84
85
window.onload=function(){
// $(function () {
$('[data-toggle="popover"]').popover()
// })
$("#show_img_btn").on("click",
function loadFont() {
var canvas = document.createElement("canvas");
canvas.width = 700;
canvas.height = 700;
// canvas.style.width = canvas.style.height = "100px";
var ctx = canvas.getContext('2d');
// function setupCanvas(canvas) {
// var dpr = window.devicePixelRatio || 1;
// var rect = canvas.getBoundingClientRect();
// canvas.width = rect.width * dpr;
// canvas.height = rect.height * dpr;
// var ctx = canvas.getContext('2d');
// ctx.scale(dpr, dpr);
// return ctx;
// }
// var text = $("#the_text").text();
// --------------------------------------VARIABLES------------------------------
var inpText = document.getElementById("textcon").value;
var selectedFont = document.getElementById("fontpick").value;
var selectedWeight = "700";
var selectedColor = document.getElementById("colorpick").value;
var selectedAlign = "center";
// --------------------------------------CTX------------------------------
ctx.font = selectedWeight + " 100px " + selectedFont;
ctx.fillStyle = selectedColor;
ctx.textAlign = selectedAlign;
var array = inpText.split("/n ");
var fontSize = 30;
if (ctx.textAlign === "left") {
var x = 20;
} else if (ctx.textAlign === "right") {
var x = (canvas.width - 20)
} else if (ctx.textAlign === "center") {
var x = (canvas.width/2)
}
var y = canvas.height/2;
for (var i = 0; i < array.length; i++) {
ctx.fillText(array[i], x, y);
y += (fontSize + 150);
}
var img = document.createElement("img");
img.src=canvas.toDataURL();
$("#show_img_here").append(img);
window.scrollBy(0,700);
scrolldelay = setTimeout(pageScroll,10);
// $("body").append(canvas);
}
);
}