-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
114 lines (106 loc) · 3.01 KB
/
edit.php
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
<html
<head>
<script src="jquery.js"></script>
<style>
body {
margin: 50px;
}
div {
border: 1px solid black;
margin: 10px;
}
img {
cursor: text;
}
input[type="text"] {
border: none;
background: transparent;
resize: both;
}
input[type="text"]:hover {
border: 1px solid black;
background: white;
}
textarea {
width: 40%;
height: 30%;
}
</style>
<script>
clicked = function(event)
{
console.log(event);
var page = $(event.srcElement).parent();
console.log(page);
var x = event.offsetX + page[0].offsetLeft;
var y = event.offsetY + page[0].offsetTop + 50; // body margin-top
var element = $('<input type="text" value="123" style="z-index:20;position:absolute;left:'+x+'px;top:'+y+'px;" id="'+x+y+'"/>');
console.log(element);
page.append(element);
element.focus();
updateJSON();
element.keyup( function(event)
{
if (event.keyCode == 27)
{
console.log('ESC');
$(this).remove();
}
updateJSON();
}
);
}
updateJSON = function()
{
var json = [];
pages = $('div.page');
for (var i=0; i<pages.length; i++)
{
var currentPage = [];
var texts = $('.page#page'+i+' input[type="text"]');
for (var j=0; j<texts.length; j++)
{
var text = $('#'+texts[j].id);
console.log(text);
var x = text.css('left').replace('px','')-$('#page'+i)[0].offsetLeft;
var y = text.css('top').replace('px','')-$('#page'+i)[0].offsetTop-50;
t = {"x":x,"y":y,"text":text.val()};
currentPage.push(t);
}
json.push(currentPage);
}
console.log(json);
$('#json').html( JSON.stringify(json,null," ") );
}
</script>
</head>
<body>
<?php
$prefix = $_GET['prefix'];
$count = $_GET['count'];
$start = $_GET['start'];
$decimals = $_GET['decimals'];
function embed_image($path)
{
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
return 'data:image/'.$type.';base64,'.base64_encode($data);
}
for ($i=$start; $i<$start+$count; $i++)
{
echo '<div class="page" id="page'.$i.'">';
echo "<h3>Page ".($i+1)." / ".$count.":</h3>";
$file = "/tmp/".$prefix."-".str_pad($i,$decimals,"0",STR_PAD_LEFT).".jpg";
echo '<img src="'.embed_image($file).'" onclick="clicked(event);"/>';
echo "</div>";
}
?>
<form action="export.php" method="post" enctype="multipart/form-data">
Text to be inserted:
<br/>
<textarea readonly="true" id="json" name="json"></textarea>
<br/>
<input type="submit" value="Insert now"/>
</form>
</body>
</html>