-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.html
560 lines (470 loc) · 17 KB
/
encoder.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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ValentineCode</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!--link rel="stylesheet/less" href="less/bootstrap.less" type="text/css" /-->
<!--link rel="stylesheet/less" href="less/responsive.less" type="text/css" /-->
<!--script src="js/less-1.3.3.min.js"></script-->
<!--append ‘#!watch’ to the browser URL, then refresh the page. -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="img/favicon.png">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<script type="text/javascript" src="./filters.js"></script>
<script type="text/javascript"> $('#myModal').modal(options) </script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav navbar-nav">
<a class="navbar-brand" href="./index.html">ValentineCode</a>
<li class="active">
<a href="./encoder.html">Encoder</a>
</li>
<li>
<a href="./decoder.html">Decoder</a>
</li>
</ul>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" class="btn-success" data-id="page-top" data-toggle="modal" data-target="#myModal"><font color="white">Inspiration</font></a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<center>
<h1>
<br>
HiddenYourSecret UnderPicture
</h1>
</center>
</div>
</div>
</div>
<div class="row clearfix">
<br>
<div class="col-md-6 column">
<center>
<canvas id="mycanvas"></canvas>
<p>
<a id="download" href="#" type="button" class="btn btn-success btn-lg" onclick="printClick()" onclick="downloadImage()">Download PNG</a>
</p>
</center>
</div>
<div class="col-md-6 column">
<div id="SuperPosition">
</div>
<div>
<center>
<a id="addbtn" href="#" type="button" class="btn btn-success" onclick="addTextForm()"> Add </a>
<a id="delbtn" href="#" type="button" class="btn btn-success" onclick="delTextForm()"> Del </a>
</center>
</div>
</div>
</div>
</div>
<script>
function printClick () {
console.log("click button");
}
</script>
<script>
var n = 0;
var backupData = [];
function addTextForm () {
backupData = [];
for (var i = 1; i <= n; i++) {
var data = [];
var t = document.getElementById('inputText'+i).value;
var x = document.getElementById('inputX'+i).value;
var y = document.getElementById('inputY'+i).value;
// var a = document.getElementById('inputA'+i).value;
var s = document.getElementById('inputS'+i).value;
// var c = document.getElementById('inputColor'+i).value;
backupData.push([t,x,y,s]);
}
n++;
xString = "<div id=\"SuperText"+n+"\" class=\"form-group\">"
+ "<p id=\"placeText"+n+"\">"
+ "<input id=\"inputText"+n+"\" type=\"email\" class=\"form-control\" placeholder=\"Input Something...\" onkeyup=\"valueUpdate(this.id)\">"
+ "</p>"
+ "<p id=\"placeStyle"+n+"\">"
+ "<label>X :</label>"
+ "<input id=\"inputX"+n+"\" type=\"range\" min=\"0\" max=\"100\" value=\"50\" style=\"width: 40px;\" id=\"fader\" oninput=\"valueUpdate(this.id)\">"
+ "<label> </label>"
+ "<label>Y :</label>"
+ "<input id=\"inputY"+n+"\" type=\"range\" min=\"0\" max=\"100\" value=\"50\" style=\"width: 45px;\" id=\"fader\" oninput=\"valueUpdate(this.id)\">"
+ "<label> </label>"
+ "<label>S :</label>"
+ "<input id=\"inputS"+n+"\" type=\"range\" min=\"0\" max=\"100\" value=\"50\" style=\"width: 45px;\" id=\"fader\" oninput=\"valueUpdate(this.id)\">"
+ "<label> </label>"
// + "<label>A :</label>"
// + "<input id=\"inputA"+n+"\" type=\"range\" min=\"0\" max=\"100\" value=\"50\" style=\"width: 45px;\" id=\"fader\" oninput=\"valueUpdate(this.id)\">"
// + "<label> </label>"
// + "<input id=\"inputColor"+n+"\" type=\"color\" value=\"#40c744\" style=\"width: 30px;\" oninput=\"valueUpdate(this.id)\"/>"
+ "</p>"
+ "</div>"
var pos = document.getElementById('SuperPosition');
pos.innerHTML += xString;
for (var i = 1; i < n; i++) {
try {
var index = i - 1;
document.getElementById('inputText'+i).value = backupData[index][0];
document.getElementById('inputX'+i) = backupData[index][1];
document.getElementById('inputY'+i) = backupData[index][2];
// document.getElementById('inputA'+i) = backupData[index][3];
document.getElementById('inputS'+i) = backupData[index][3];
// document.getElementById('inputColor'+i) = backupData[index][5];
}
catch (err) {
}
}
}
addTextForm();
addTextForm();
</script>
<script>
function delTextForm() {
if (n > 1) {
var x = document.getElementById('SuperText'+n);
n--;
x.parentNode.removeChild(x);
}
}
</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Inspiration</h4>
</div>
<div class="modal-body">
<center>
<a href="http://mathminton.blogspot.com/2011/01/steganography.html"><h4>http://mathminton.blogspot.com/2011/01/steganography.html</h4></a> <br>
<img src="mathLove1.png" width="500px" height="271px"></img>
<br><br>
<img src="mathLove2.png" width="500px" height="271px"></img>
</center>
</div>
<div class="modal-footer">
<a href="#" type="button" class="btn btn-danger" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="http://counter1.allfreecounter.com/private/countertab.js?c=57243b5edfb2a9a3337e39edc3adf5c6"></script>
</body>
<script>
var self = this;
var image = document.createElement("img");
var canvas = document.getElementById("mycanvas"),
ct = canvas.getContext("2d");
image.src = './normal.png';
function clearObjCanvas () {
ct.clearRect(0, 0, canvas.width, canvas.height);
}
function drawImageCanvas() {
clearObjCanvas();
ct.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
console.log('gg');
}
function render () {
}
</script>
<script>
var textData = [];
function valueUpdate (id) {
textData = [];
for (var i = 1; i <= n; i++) {
var data = [];
var t = document.getElementById('inputText'+i).value;
var x = document.getElementById('inputX'+i).value;
var y = document.getElementById('inputY'+i).value;
// var a = document.getElementById('inputA'+i).value;
var s = document.getElementById('inputS'+i).value;
// var c = document.getElementById('inputColor'+i).value;
textData.push([t,x,y,s]);
}
renderCanvas();
}
// function doCanvas() {
// /* draw something */
// ctx.fillStyle = '#f90';
// ctx.fillRect(0, 0, canvas.width, canvas.height);
// ctx.fillStyle = '#fff';
// ctx.font = '60px sans-serif';
// ctx.fillText('Drag', 10, canvas.height / 2 - 15);
// ctx.font = '26px sans-serif';
// ctx.fillText('Image Here', 15, canvas.height / 2 + 35);
// }
function drawText () {
for (var i = 1; i <= n; i++) {
try {
var index = i - 1;
var text = textData[index][0];
var xVal = textData[index][1];
var yVal = textData[index][2];
// var angleVal = (textData[index][3] - 50) * 180 / 50.0;
// console.log(angleVal)
var sizeVal = textData[index][3];
var colorVal = '#000000';
// ct.fillStyle = '#fff';
ct.fillStyle = colorVal;
// ct.font = '120px sans-serif';
// console.log(sizeVal + 20);
ct.font = (parseInt(sizeVal) / 100.0 * (180 - 20) + 20)+'px sans-serif';
var xPos = canvas.width * xVal / 100;
var yPos = canvas.height * (100 - yVal) / 100;
// ct.rotate(
ct.textAlign="center";
// console.log(text);
ct.fillText(text, xPos, yPos);
// ct.rotate(-angleVal*Math.PI/180);
// ct.translate(-xPos, -yPos);
}
catch(err) {
}
}
}
function renderCanvas () {
drawImageCanvas();
drawText();
}
</script>
<script>
(function () {
var canvas = document.getElementById("mycanvas"),
context = canvas.getContext("2d"),
img = document.createElement("img"),
mouseDown = false,
brushColor = "rgb(0, 0, 0)",
hasText = true,
clearCanvas = function () {
if (hasText) {
context.clearRect(0, 0, canvas.width, canvas.height);
hasText = false;
}
};
// Adding instructions
context.fillText("Drop an image onto the canvas", 240, 200);
context.fillText("Click a spot to set as brush color", 240, 220);
// Image for loading
img.addEventListener("load", function () {
clearCanvas();
if (img.width > 480 || img.height > 480) {
if (img.width / 480.0 >= img.height / 480.0) {
canvas.width = 480;
canvas.height = 480.0 * img.height / img.width;
}
else {
canvas.height = 480;
canvas.width = 480.0 * img.width / img.height;
}
}
else {
canvas.width = img.width;
canvas.height = img.height;
}
console.log('Image for loading');
self.image = img;
// drawImageCanvas();
renderCanvas();
// context.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
}, false);
// Detect mousedown
// canvas.addEventListener("mousedown", function (evt) {
// clearCanvas();
// mouseDown = true;
// context.beginPath();
// console.log('Detect mousedown');
// }, false);
// Detect mouseup
// canvas.addEventListener("mouseup", function (evt) {
// mouseDown = false;
// var colors = context.getImageData(evt.layerX, evt.layerY, 1, 1).data;
// brushColor = "rgb(" + colors[0] + ", " + colors[1] + ", " + colors[2] + ")";
// console.log('Detect mouseup');
// }, false);
// Draw, if mouse button is pressed
canvas.addEventListener("mousemove", function (evt) {
if (mouseDown) {
context.strokeStyle = brushColor;
context.lineWidth = 20;
context.lineJoin = "round";
context.lineTo(evt.layerX+1, evt.layerY+1);
context.stroke();
console.log('Draw, if mouse button is pressed');
}
}, false);
// To enable drag and drop
canvas.addEventListener("dragover", function (evt) {
evt.preventDefault();
}, false);
// Handle dropped image file - only Firefox and Google Chrome
canvas.addEventListener("drop", function (evt) {
var files = evt.dataTransfer.files;
if (files.length > 0) {
var file = files[0];
if (typeof FileReader !== "undefined" && file.type.indexOf("image") != -1) {
var reader = new FileReader();
// Note: addEventListener doesn't work in Google Chrome for this event
reader.onload = function (evt) {
img.src = evt.target.result;
};
reader.readAsDataURL(file);
}
}
evt.preventDefault();
}, false);
})();
</script>
<script>
var canvas = document.getElementById('mycanvas'),
ctx = canvas.getContext('2d');
canvas.height = 500;
canvas.width = 397;
function doCanvas() {
/* draw something */
//ctx.fillStyle = '#f90';
ctx.fillRect(0, 0, canvas.width, canvas.height);
eiei = document.createElement('img');
eiei.src = './robot_ku.png';
setTimeout(function() {
ctx.drawImage(eiei, 0, 0, canvas.width, canvas.height);
},1000);
//canvas.height = 480;
//canvas.width = 480;
//ctx.fillStyle = '#fff';
//ctx.font = '60px sans-serif';
//ctx.fillText('Drag', 10, canvas.height / 2 - 15);
//ctx.font = '26px sans-serif';
//ctx.fillText('Image Here', 15, canvas.height / 2 + 35);
}
function downloadCanvas(link, canvasId, filename) {
// link.href = document.getElementById(canvasId).toDataURL();
// link.download = filename;
var textCanvas = document.createElement('canvas'); // use textCanvas // don't forgot rgb scale
textCanvas.width = image.width;
textCanvas.height = image.height;
var textContext = textCanvas.getContext("2d");
textContext.rect(0, 0, textCanvas.width, textCanvas.height);
textContext.fillStyle = "#A4A4A4";
textContext.fill();
for (var i = 1; i <= n; i++) {
try {
// context.fill()
var index = i - 1;
var text = textData[index][0];
var xVal = textData[index][1];
var yVal = textData[index][2];
// var angleVal = (textData[index][3] - 50) * 180 / 50.0;
// console.log(angleVal)
var sizeVal = textData[index][3];
var colorVal = '#BDBDBD';
// ct.fillStyle = '#fff';
textContext.fillStyle = colorVal;
// ct.font = '120px sans-serif';
// console.log(sizeVal + 20);
textContext.font = (parseInt(sizeVal) / 100.0 * (180 - 20) + 20)+'px sans-serif';
var xPos = image.width * xVal / 100;
var yPos = image.height * (100 - yVal) / 100;
// ct.rotate(
textContext.textAlign="center";
// console.log(text);
textContext.fillText(text, xPos, yPos);
// ct.rotate(-angleVal*Math.PI/180);
// ct.translate(-xPos, -yPos);
}
catch(err) {
}
//TEST Code
var dummyCanvas = document.createElement('canvas');
var dummyContext = dummyCanvas.getContext('2d');
dummyCanvas.width = image.width;
dummyCanvas.height = image.height;
// dummyContext.drawImage(image, 0, 0, image.width, image.height, 0, 0, image.width, image.height);
dummyContext.drawImage(image, 0, 0, image.width, image.height)
// console.log(image.width);
// console.log(image.height);
// console.log(dummyCanvas.width);
// console.log(dummyCanvas.height);
var pixelsCode = textContext.getImageData(0,0,image.width,image.height);
// console.log(pixelsCode);
var pixelsImg = dummyContext.getImageData(0,0,image.width,image.height);
// var imageData = createImageData(pixelsImg.width, pixelsImg.height);
// var codeData = createImageData(pixelsCode.width, pixelsCode.height);
// var output = createImageData(pixelsImg.width, pixelsImg.height);
// var dst = output.data;
var d = pixelsImg.data;
// console.log(d.data);
var e = pixelsCode.data;
for (var i=0; i<d.length; i+=4) {
var r = e[i];
var g = e[i+1];
var b = e[i+2];
// if (r!=68 && r!=255) {
// console.log('yeah');
// };
var gs = 0.3*r + 0.59*g + 0.11*b; // greyScale
pixelsImg.data[i] = Math.floor(pixelsImg.data[i] / 4)*4 + gs%4;
pixelsImg.data[i+1] = Math.floor(pixelsImg.data[i+1] / 8)*8 + Math.floor(gs/4)%8;
pixelsImg.data[i+2] = Math.floor(pixelsImg.data[i+2] / 8)*8 + Math.floor(gs/32);
// d[i] = r;
// d[i+1] = g;
// d[i+2] = b;
// var v = pixelsImg.data[i]%4 + pixelsImg.data[i+1]%8*4 + pixelsImg.data[i+2]%8*32;
// pixelsImg.data[i] = pixelsImg.data[i+1] = pixelsImg.data[i+2] = v;
// // d[i] = d[i+1] = d[i+2] = gs;
}
//TEST Code
// d = e;
// var dummyCanvas = document.createElement('canvas');
// pixelsImg.data = d.data;
var downloadResultCanvas = document.createElement('canvas');
downloadResultCanvas.width = image.width;
downloadResultCanvas.height = image.height;
var downloadResultContext = downloadResultCanvas.getContext('2d');
downloadResultContext.putImageData(pixelsImg,0,0);
// console.log('eieiei')
// console.log(downloadResultCanvas.width);
// console.log('eieiei')
link.href = downloadResultCanvas.toDataURL();
link.download = filename;
}
}
document.getElementById('download').addEventListener('click', function() {
var textCanvas = document.createElement('canvas');
downloadCanvas(this, 'mycanvas', 'test.png');
}, false);
doCanvas();
//drawImageCanvas();
</script>
</html>