-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
109 lines (86 loc) · 2.41 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
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<style>
body
{
padding: 3px;
font-size: 20pt;
}
</style>
<body style="text-align:center;">
<br>
<b>Send photo by SMS</b>
<br><br><br>
1. Twilio phone number:<br>
<input id='pn' type="tel" style='font-size:125%' placeholder="(eg: +32460123456)"><br><br>
<img id='res'>
<div id='test' style='border:1px solid black; border-radius:5px;background:lightblue' onclick='test()'>2. Take photo<br>& send it by SMS</div>
<div id='status'></div>
<div id='progress'></div>
</html>
<script src="jquery-1.12.1.js"></script>
<script src="cordova.js"></script>
<script>
//some inspiration from https://zocada.com/compress-resize-images-javascript-browser/
function test()
{
navigator.camera.getPicture(onSuccess, onFail, { quality: 5, destinationType: Camera.DestinationType.DATA_URL});
}
function onSuccess(imageData)
{
const width = 200;
const height = 120;
var res = "data:image/jpeg;base64," + imageData;
const img = new Image();
console.log(res.length, res)
img.src = res;
img.onload = function()
{
const elem = document.createElement('canvas');
elem.width = width;
elem.height = height;
const ctx = elem.getContext('2d');
// img.width and img.height will contain the original dimensions
ctx.drawImage(img, 0, 0, width, height);
console.log(ctx)
cu = ctx.canvas.toDataURL('image/jpeg', 1.0);
console.log(cu.length, cu);
$('#res').attr('src', cu)
var L = 145
var N = Math.ceil(cu.length/L)
var id = Math.floor(Math.random()*100)
//#99,9999,9999#
var i = 0;
sendLine()
$('#status').text('sending')
var pn = $('#pn').val()
function sendLine()
{
$('#progress').text($('#progress').text() + '*')
setTimeout(function()
{
var txt = '#' + id + '#' + i + '#' + N + '#' + cu.substr(i*L, L)
console.log(txt)
SMS.sendSMS(pn, txt, function(){console.log('OK')}, function(){console.log('ERROR')});
if (i < N-1)
{
++i
sendLine()
}
else
{
$('#status').text('sent')
}
}, 5000)
}
}
// should enable error correction
// eg one or 2 strings allowing to recompute 1 or 2 missing data strings
}
function onFail(message)
{
alert('Failed because: ' + message);
}
</script>
</body>