-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
254 lines (200 loc) · 7.25 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
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
<html>
<head>
<title>base64 image encoder & decoder</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script>
$(function() {
var ctx = $('#mycanvas')[0].getContext('2d');
ctx.font = "20px Arial";
ctx.fillText("uploaded or decoded", $('#mycanvas')[0].width / 5.2, $('#mycanvas')[0].height / 2);
ctx.fillText("image", $('#mycanvas')[0].width / 2.3, 170);
//copy function
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
$('#decodeArea').bind('click', function(event) {
$('#decodeArea').select();
});
$('#copyButton').bind('click', function(event) {
copyToClipboard('.one-line');
});
$('#viewButton').bind('click', function(event) {
if (!$.trim($("#decodeArea").val())) {
// textarea is empty or contains only white-space
} else {
$('#mycanvas').fadeOut("slow", function() {
$('#decodedImage').attr("src", $("#decodeArea").val());
$('#decodedImage').show();
});
}
});
var temp = undefined;
$('#toggleButton').bind('click', function(event) {
if ($('#toggleButton').hasClass('css')) {
$('.one-line').html(temp);
$('#toggleButton').removeClass('css');
} else {
$('.one-line').html('background-image: url(\'' + $('.one-line').html() + '\');');
$('#toggleButton').addClass('css');
}
});
$('#imageinput').bind('change', function(event) {
$('#mycanvas').show();
$('#decodedImage').hide();
var myCanvas = $('#mycanvas')[0];
var ctx = myCanvas.getContext('2d');
var img = new Image();
img.onload = function() {
myCanvas.width = img.width;
myCanvas.height = img.height;
ctx.drawImage(img, 0, 0);
var multiline = myCanvas.toDataURL('image/png');
var singleline = multiline.replace(/(\r\n|\n|\r)/gm, "");
$('.one-line').html(singleline);
temp = singleline;
};
img.src = URL.createObjectURL(event.target.files[0]);
});
});
</script>
<style>
.selectable {
-webkit-touch-callout: all;
/* iOS Safari */
-webkit-user-select: all;
/* Safari */
-khtml-user-select: all;
/* Konqueror HTML */
-moz-user-select: all;
/* Firefox */
-ms-user-select: all;
/* Internet Explorer/Edge */
user-select: all;
/* Chrome and Opera */
}
.one-line {
width: 85%;
height: 70px;
padding: 1em;
overflow: scroll;
background-color: #ecf0f1;
}
body {
padding-top: 50px;
font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
}
.create-section {
margin-top: 4%;
}
.create-section .view-section {
padding: 40px 15px;
text-align: center;
}
.image-viewer {
padding: 20px;
}
.navbar-custom {
background-color: #e74c3c;
color: #ffffff;
border-radius: 0;
font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
}
.footer {
background-color: #e74c3c;
font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
border-radius: 0;
color: #ffffff;
}
.vcenter {
display: inline-block;
vertical-align: middle;
float: none;
}
.toggleButton {
width: 30px;
height: 30px;
margin-right: 10px;
}
.disableButton {
width: 30px;
height: 30px;
}
.canvas,
.decodedImage {
border: antiquewhite;
border-style: double;
margin: auto;
display: block;
}
textarea {
resize: none;
}
</style>
</head>
<body>
<nav class="navbar navbar-custom navbar-fixed-top">
<a href="https://github.com/akursat/base64"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/c6625ac1f3ee0a12250227cf83ce904423abf351/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_gray_6d6d6d.png"></a>
<div class="container">
<div class="text-center">
<h4>Base64 image encoder & decoder</h3>
</div>
</div>
</nav>
<div class="col-md-2"></div>
<div class="container">
<div class="create-section row">
<div class="line-one">
<div class="upload-button row">
<h3 class="text-center">ENCODE</h3>
<hr />
<input type="file" id="imageinput" class="btn btn-default btn-md center-block" />
<hr />
</div>
<div class="col-md-2"></div>
<div class="row col-md-8">
<button type="button" id="toggleButton" class="glyphicon glyphicon-forward pull-left vcenter toggleButton"></button>
<div class="one-line vcenter selectable"></div>
<button type="button" id="copyButton" class="btn btn-info btn-md pull-right vcenter">Copy!</button>
</div>
</div>
<div class="line-two">
<div class="multi-line-toggled"></div>
</div>
</div>
<div class="row text-center">
<hr />
<h1>OR</h1>
<hr />
<h3>DECODE</h3>
</div>
<div class="row text-center">
<div class="col-md-2"></div>
<div class="row col-md-8">
<button type="button" id="disableButton" disabled="true" class="glyphicon glyphicon-hand-up pull-left vcenter disableButton"></button>
<textarea id="decodeArea" rows="3" cols="87" placeholder="Paste your code here..."></textarea>
</textarea>
<button type="button" id="viewButton" class="btn btn-info btn-md pull-right vcenter">View!</button>
</div>
</div>
<div class="view-section row">
<div class="image-viewer">
<canvas width="300" height="300" id="mycanvas" class="canvas" ></canvas>
<img id="decodedImage" class="decodedImage" src="">
</div>
</div>
</div>
<div class="footer navbar-custom navbar-fixed-bottom text-center">
<h4>2017 / creator: akursat / <span title="not ready :(">pay a coffee</a> </h4>
</div>
</body>
</html>