-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
167 lines (129 loc) · 4.93 KB
/
index.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
canvas { border: 1px solid black; }
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:400,400i,700" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
Declarație: <select id="decl">
<option value="#E6383F">FALS</option>
<option value="#F08283">PARȚIAL FALS</option>
<option value="#373737">NEUTRU</option>
<option value="#9FD6D0">PARȚIAL ADEVĂRAT</option>
<option value="#27B198">ADEVĂRAT</option>
</select> <br> <br>
<a href="https://www141.lunapic.com/editor/?action=quick-upload.php" target="_blank">Crop Tool</a> |
Link poza: <input name="url-poza" value="https://i.imgur.com/dbK1dCy.gif"> <br>
Declarație: <textarea name="quote" rows="7" cols="20">E important să ştim cu cine vorbim şi dacă mă uit la tine să ştiu că tu eşti tu.</textarea> <br>
Nume: <input name="nume" value="Liviu Dragnea"> <br>
Funcție: <input name="functie" value="Futător de stat paralelipied"> <br>
Data și sursa: <input name="datasursa" value="31.02.0000 | hoțnews.ro"> <br>
Filename: <input name="filename" value="factual.png"><br>
<button id="render">render</button><br>
<a id="download" download="Canvas.png" href="#">Download</a>
</div>
<div class="col">
<canvas id="cnv" width="32" height="32"></canvas><br><br>
</div>
</div>
<script src="https://unpkg.com/jquery"></script>
<script>
function render() {
var width = 660;
var height = 660;
var filename = $('[name=filename]').val();
var decl = $('#decl').val();
var quote = $('[name=quote]').val();
var nume = $('[name=nume]').val();
var functie = $('[name=functie]').val();
var datasursa = $('[name=datasursa]').val();
var verdict = $('#decl option:selected').text();
var verdpoz = 700 - verdict.length / 2;
var canvas = $("#cnv")[0];
$(canvas).attr({width: width, height: height});
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
function r(ctx, x, y, w, h, c) {
ctx.beginPath();
ctx.rect(x, y, w, h);
ctx.strokeStyle = c;
ctx.stroke();
}
r(ctx, 0, 0, 32, 32, "black");
r(ctx, 4, 4, 16, 16, "red");
r(ctx, 8, 8, 16, 16, "green");
r(ctx, 12, 12, 16, 16, "blue");
ctx.fillStyle = "white";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = decl;
ctx.fillRect(0, 0, width, width*10/100);
ctx.fillRect(0, height-20, width, 20);
ctx.fillRect(width-280, height-70, width, 70);
ctx.moveTo(width-280, height-70);
ctx.lineTo(width-240, height-20);
ctx.lineTo(width-320, height-20);
ctx.fill();
var paleta = new Image();
paleta.addEventListener('load', function() {
ctx.drawImage(paleta, 510, 16) }, false);
paleta.src = 'paleta.png';
var poza = new Image();
poza.addEventListener('load', function() {
ctx.drawImage(poza, 35, 110, 190, 190) }, false);
poza.src = $('[name=url-poza]').val();
//spagetti from the internet for a textarea
var totalLines = 1;
function wrapText(context, text, x, y, maxWidth, lineHeight) {
var words = text.split(' ');
var line = '';
for(var n = 0; n < words.length; n++) {
var testLine = line + words[n] + ' ';
var metrics = ctx.measureText(testLine);
var testWidth = metrics.width;
if (testWidth > maxWidth && n > 0) {
ctx.fillText(line, x, y);
line = words[n] + ' ';
y += lineHeight;
totalLines = totalLines + 1;
}
else {
line = testLine;
}
}
ctx.fillText(line, x, y);
}
var maxWidth = 595;
var lineHeight = 20;
var x = 35;
var y = 345;
var text = quote;
ctx.font = 'italic 16pt Roboto Condensed, sans-serif';
ctx.fillStyle = '#333';
wrapText(ctx, text, x, y, maxWidth, lineHeight);
var endQuote = totalLines*23 + 355;
ctx.font = "bold 16pt Roboto Condensed, sans-serif";
ctx.fillText(nume, 35, endQuote);
ctx.font = "16pt Roboto Condensed, sans-serif";
ctx.fillText(functie, 35, totalLines*24+375);
ctx.font = "13pt Roboto Condensed, sans-serif";
ctx.fillText(datasursa, 35, 632);
ctx.font = "bold 15pt Roboto Condensed, sans-serif";
ctx.fillStyle= "white";
ctx.fillText(verdict, (500-verdict.length*6), 630);
var dt = canvas.toDataURL('image/png');
dt = dt.replace(/^data:image\/[^;]*/, 'data:application/octet-stream');
dt = dt.replace(/^data:application\/octet-stream/, 'data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=' + $('#download').attr('download'));
$('#download').attr('href', dt);
$('#download').attr('download', filename);
}
$('#render').click(render);
</script>
</div>
</body></html>