-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeme_formatter.html
More file actions
445 lines (379 loc) · 12.7 KB
/
meme_formatter.html
File metadata and controls
445 lines (379 loc) · 12.7 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!DOCTYPE html>
<html>
<head>
<title>LMAOBot</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="LMAOBot is an innovative Discord bot equipped with a dank soundboard. You can use Discord's chat function to give lmaobot commands, to which the bot sends a response. lmaobot uses the lmao prefix.">
<link rel="stylesheet" href="./css/libs/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="shortcut icon" type="image/x-icon" href="./assets/LMAO_logo.jpg"/>
<style>
body {
font-family: "Lato", sans-serif
}
canvas {
box-shadow: rgb(0, 0, 0) 0px 0px 10px;
}
.smallScreenNav {
display: none
}
.canvas-container {
margin: 1%;
display: block;
margin-left: auto;
margin-right: auto;
}
.toolbar {
margin: 1%;
}
.toolbar input, .toolbar select {
margin: 2.5px;
padding: 5px;
border-radius: 10px;
}
</style>
</head>
<body>
<!-- Navbar -->
<div class="w3-top">
<div class="w3-bar w3-black w3-card">
<a class="w3-bar-item w3-button w3-padding-large w3-hide-medium w3-hide-large w3-right" href="javascript:void(0)" onclick="setup_navbar()" title="Toggle Navigation Menu"><i class="fa fa-bars"></i></a>
<a href="/" class="w3-bar-item w3-button w3-padding-large">LMAOBOT</a>
<a href="#" class="w3-bar-item w3-button w3-padding-large w3-hide-small w3-right">MEME FORMATTER</a>
<a href="/#commands" class="w3-bar-item w3-button w3-padding-large w3-hide-small w3-right">COMMANDS</a>
<a href="/#invite" class="w3-bar-item w3-button w3-padding-large w3-hide-small w3-right">INVITE</a>
</div>
</div>
<!-- Navbar on small screens -->
<div id="smallScreenNav" class="w3-bar-block w3-black w3-hide w3-hide-large w3-hide-medium w3-top" style="margin-top:46px">
<a href="/#invite" class="w3-bar-item w3-button w3-padding-large">INVITE</a>
<a href="/#commands" class="w3-bar-item w3-button w3-padding-large">COMMANDS</a>
<a href="#" class="w3-bar-item w3-button w3-padding-large">MEME FORMATTER</a>
</div>
<!-- Start Page content -->
<div class="w3-content" style="max-width: 2000px; margin-top: 46px; text-align: center; align-content: center;">
<canvas style="margin: 5px;" width="800" height="600" id="master_canvas"><b>HTML Canvas isn't supported...</b></canvas>
<form class="toolbar">
<input type="file" onchange="load_background(this.files[0]);" accept=".jpg, .png" style="display: none;" name="image_file" />
<input type="button" onclick="image_file.click();" value="Open image..." />
<br />
<select name="add_type">
<option value="rectangle">
Square
</option>
<option value="circle">
Circle
</option>
</select>
<br />
<input type="button" onclick="new new_step('text', add_type.value)" value="Add Text" name="add_text" />
<input type="button" onclick="new new_step('image', add_type.value)" value="Add Image" name="add_image" />
<br />
<input type="button" onclick="export_format();" value="Export" name="export" />
<input type="file" onchange="import_format(this.files[0]);" style="display: none;" name="format_file" />
<input type="button" value="Import" onclick="format_file.click();" name="import" />
</form>
</div>
<!-- End Page Content -->
<!-- Footer -->
<footer class="w3-container w3-padding-64 w3-center w3-opacity w3-light-grey w3-xlarge">
<p class="w3-medium">© LMAOBOT ALL RIGHTS RESERVED. 2018></p>
</footer>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-117753493-1"></script>
<script>
// Used to toggle the menu on small screens when clicking on the menu button
function setup_navbar() {
var x = document.getElementById("smallScreenNav");
if (x.className.indexOf("w3-show") == -1) {
x.className += " w3-show";
} else {
x.className = x.className.replace(" w3-show", "");
}
}
</script>
<script src="./js/libs/fabric.min.js"></script>
<script>
// Setup global variables
var canvas;
var meme = {
name: '',
data: undefined
};
var steps = [];
// Setup Fabric.js on page load
window.onload = function () {
// Setup Canvas
canvas = new fabric.Canvas('master_canvas');
canvas.setBackgroundColor('black', canvas.renderAll.bind(canvas));
canvas.on({
// Desktop/Keyboard/Mouse events
'mouse:down': function(opt) {
if (opt.e.ctrlKey) {
this.isDragging = true;
this.selection = false;
this.lastPosX = opt.e.clientX;
this.lastPosY = opt.e.clientY;
}
},
'mouse:move': function(opt) {
if (this.isDragging) {
this.viewportTransform[4] += opt.e.clientX - this.lastPosX;
this.viewportTransform[5] += opt.e.clientY - this.lastPosY;
canvas.requestRenderAll();
this.lastPosX = opt.e.clientX;
this.lastPosY = opt.e.clientY;
}
},
'mouse:up': function(opt) {
this.isDragging = false;
this.selection = true;
},
'mouse:wheel': function(opt) {
var delta = opt.e.deltaY;
var pointer = canvas.getPointer(opt.e);
// Zoom amount
var zoom;
if (opt.e.ctrlKey) {
zoom = canvas.getZoom() - delta / 25;
} else {
zoom = canvas.getZoom() - delta / 75;
}
// Limit zoom
zoom = Math.min(20, Math.max(0.01, zoom));
canvas.zoomToPoint({
x: opt.e.offsetX,
y: opt.e.offsetY
}, zoom);
opt.e.preventDefault();
opt.e.stopPropagation();
},
// Mobile/Touch events
'touch:gesture': function(opt) {
if (opt.e.touches && opt.e.touches.length == 2) {
pausePanning = true;
var point = new fabric.Point(opt.self.x, opt.self.y);
if (opt.self.state == "start") {
zoomStartScale = self.canvas.getZoom();
}
var delta = zoomStartScale * opt.self.scale;
self.canvas.zoomToPoint(point, delta);
pausePanning = false;
}
},
'object:selected': function() {
pausePanning = true;
},
'selection:cleared': function() {
pausePanning = false;
},
'touch:drag': function(opt) {
if (pausePanning == false && undefined != opt.e.layerX && undefined != opt.e.layerY) {
currentX = opt.e.layerX;
currentY = opt.e.layerY;
xChange = currentX - lastX;
yChange = currentY - lastY;
if ((Math.abs(currentX - lastX) <= 50) && (Math.abs(currentY - lastY) <= 50)) {
var delta = new fabric.Point(xChange, yChange);
canvas.relativePan(delta);
}
lastX = opt.e.layerX;
lastY = opt.e.layerY;
}
}
});
// Setup resize
window.addEventListener("resize", resize_canvas);
resize_canvas();
}
/**
* Exports current Steps into a format.
* @return {undefined} Returns nothing.
*/
function export_format() {
if (meme.data === undefined) return alert('You haven\'t loaded a image!');
var format = {
image: meme.data,
steps: []
}
for (var step in steps) {
format.steps.push(steps[step].export());
}
// Setting up a DOM is necessary for downloads in some Browsers
var download = document.createElement('a');
download.setAttribute('href', 'data:text/JSON,' + JSON.stringify(format));
download.setAttribute('download', meme.name + '.json');
document.body.appendChild(download);
download.click();
download.remove();
}
/**
* Imports Steps from a format.
* @param {File} [format_file] File that's a format; .json.
* @return {undefined} Returns nothing.
*/
function import_format(format_file) {}
/**
* Generate a random RGB color.
* @return {Array} Returns a Array, containing three integers, representing a random RGB color.
*/
function randomRGB() {
return [Math.floor(Math.random() * 255), Math.floor(Math.random() * 255), Math.floor(Math.random() * 255)];
}
/**
* Given a RGB object return a RGB string.
* @param {Array} [rgb] Array representing RGB; [ Red, Green, Blue ].
* @return {String} Returns a string representing a RGB color.
*/
function stringRGB(rgb) {
return 'rgb(' + Math.floor(rgb[0]) + ',' + Math.floor(rgb[1]) + ',' + Math.floor(rgb[2]) + ')';
}
/**
* Given a RGB object and alpha return a RGBA string.
* @param {Array} [rgb] Array representing RGB; [ Red, Green, Blue ].
* @param {Integer} [alpha] Alpha amount; Range: 0 - 1.
* @return {String} Returns a string representing a RGBA color.
*/
function stringRGBA(rgb, alpha) {
// Make sure alpha is valid
if (alpha == undefined) {
alpha = 1;
} else if (alpha < 0) {
alpha = 0;
} else if (alpha > 1) {
alpha = 1;
}
return 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ',' + alpha + ')';
}
/**
* Resize Canvas and it's content.
* @return {undefined} Returns nothing.
*/
function resize_canvas() {
// Resize Canvas
canvas.setWidth(window.innerWidth - 100);
canvas.setHeight(window.innerHeight - 100);
// Fix background image for Canvas
if (canvas.backgroundImage !== null) {
canvas.backgroundImage.left = canvas.width / 2;
canvas.backgroundImage.top = canvas.height / 2;
if (canvas.width < canvas.height * 1.30) {
canvas.backgroundImage.scaleToWidth(canvas.width * 0.75);
} else {
canvas.backgroundImage.scaleToHeight(canvas.height * 0.75);
}
}
// Fix Canvas's content
canvas.calcOffset();
canvas.requestRenderAll();
}
/**
* Load background for the Canvas.
* @param {image_file} [image] A image file.
* @return {undefined} Returns nothing.
*/
function load_background(image_file) {
var reader = new FileReader();
// Once file has been read do the following
reader.addEventListener('load', function () {
// Setup Meme info
meme.name = image_file.name;
meme.data = reader.result.replace(/^data:image\/(png|jpg);base64,/, "");
new fabric.Image.fromURL(reader.result, function (image) {
// Set Image to center
image.originX = image.originY = 'center';
image.left = canvas.width / 2;
image.top = canvas.height / 2;
// Resize Image to fit Canvas
if (canvas.width < canvas.height * 1.30) {
image.scaleToWidth(canvas.width * 0.75);
} else {
image.scaleToHeight(canvas.height * 0.75);
}
// Set Canvas background
canvas.setBackgroundImage(image);
canvas.requestRenderAll();
});
});
// Read image if any given
if (image_file) {
reader.readAsDataURL(image_file)
}
}
/**
* Create a Step in Canvas.
* @param {string} [step_type] Type of Step to create; default: text - options: text, image.
* @param {string} [step_shape] Shape of Step; default: rectangle - options: rectangle, circle.
* @return {Object} Returns instance of step.
*/
function new_step(step_type, step_shape) {
this.id = steps.push(this) - 1;
this.type = step_type;
this.shape = step_shape;
this.color = randomRGB();
this.content = new fabric.Group([], {
lockScalingFlip: true,
fill: 'rgba(0, 0, 0, 0)',
backgroundColor: 'rgba(0, 0, 0, 0)'
});
if (step_shape === 'rectangle') {
this.content.addWithUpdate(new fabric.Rect({
originX: 'center',
originY: 'center',
width: 190,
height: 120,
stroke: stringRGB(this.color),
strokeWidth: 3,
fill: 'rgba(0, 0, 0, 0)',
backgroundColor: 'rgba(0, 0, 0, 0)'
}));
} else if (step_shape === 'circle') {
this.content.addWithUpdate(new fabric.Circle({
originX: 'center',
originY: 'center',
radius: 100,
stroke: stringRGB(this.color),
strokeWidth: 3,
fill: 'rgba(0, 0, 0, 0)',
backgroundColor: 'rgba(0, 0, 0, 0)'
}));
}
this.content.addWithUpdate(new fabric.Text((this.id + 1) + '\n' + step_type, {
minScaleLimit: 1,
originX: 'center',
originY: 'center',
fontSize: 12,
textAlign: 'center',
fill: 'rgb(255, 255, 255)',
backgroundColor: 'rgba(0, 0, 0, 0)'
}));
canvas.add(this.content);
this.content.center();
canvas.requestRenderAll();
this.export = function () {
return {
type: this.type,
shape: this.shape,
size: [
Math.floor(this.content._objects[0].width),
Math.floor(this.content._objects[0].height)
],
position: [
Math.floor(this.content.left),
Math.floor(this.content.top)
]
};
}
return this;
}
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-117753493-1');
</script>
</body>
</html>