-
Notifications
You must be signed in to change notification settings - Fork 35
/
manual.php
executable file
·276 lines (218 loc) · 7.83 KB
/
manual.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
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
<?php
session_start();
require_once('library/odf.php');
$base = $_SESSION["base"]; //Getting file name with filled Institute Details
$odf = new odf("odt/base/$base.odt"); //Initializing the object with above file name
$id = uniqid();
$_SESSION['id'] = $id; //To be used with filenames to differentiate simultaneous files being processed
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
// Assigning Form data to sesssion variables to be used in next step.
$_SESSION['sal'] = $_POST["sal"];
$_SESSION['fname'] = $_POST["fname"];
$_SESSION['mname'] = $_POST["mname"];
$_SESSION['lname'] = $_POST["lname"];
$_SESSION['ins'] = $_POST["ins"];
$_SESSION['city'] = $_POST["city"];
$_SESSION['state'] = $_POST["state"];
//assigning image name to variable photo.
$photo = "$id".strtok($_FILES["file"]["name"],"."); //using strtok() to store filename without extension
$_SESSION['photo'] = $photo; //Assigning Photo variable to session vatriable
/*************************************** Image Validation********************************************/
// Link to the other file if any of following condition fails
$url = "<meta http-equiv='Refresh' content='3; URL=option.php?var=manual'>";
if($_FILES["file"]["name"] == Null) //checks if no file is selected
{
echo "<center><strong>No Image Selected!</strong></center>";
echo $url;
exit;
}
if($_FILES["file"]["size"] > 400144) //Size validation Condition(should be less than 400kb)
{
echo "<center><strong>Image Size Exceeded...</strong></center>";
echo $url;
exit;
}
//moving the uploaded file to directory
move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/manual/" .$photo);
$photo_path = "uploads/manual/$photo"; //storing path of uploaded photo in variable
//Checking the type of uploaded Image file
if ($_FILES["file"]["type"] == "image/gif")
$origin = imagecreatefromgif($photo_path);
elseif($_FILES["file"]["type"] == "image/jpeg")
$origin = imagecreatefromjpeg($photo_path);
elseif($_FILES["file"]["type"] == "image/jpg")
$origin = imagecreatefromjpeg($photo_path);
elseif($_FILES["file"]["type"] == "image/png")
$origin = imagecreatefrompng($photo_path);
//In case of any other format of uploaded file
else
{
echo "<center><strong>Invalid Image File...</strong></center>";
echo $url;
exit;
}
$originWidth = imagesx($origin); //Width of original uploaded image
$originHeight = imagesy($origin); //Height of original uploaded image
//creating another image to which the original image is copied
$destination = imageCreateTrueColor( $originWidth, $originHeight );
//Copying the original uploaded image to new created one
imagecopyresampled($destination,$origin,0,0,0,0,$originWidth,$originHeight,$originWidth,$originHeight);
//Finally saving the image as jpeg in directory to be used by cropping tool
imagejpeg($destination,"uploads/manual/src.jpg",100);
}
else
{
//Using Session variables to fetch form data
$name = $_SESSION['sal'];
$fname = $_SESSION['fname'];
$mname = $_SESSION['mname'];
$lname = $_SESSION['lname'];
$ins = $_SESSION['ins'];
$city = $_SESSION['city'];
$state = $_SESSION['state'];
$photo = $_SESSION['photo'];
$id = $_SESSION['id'];
$targ_w = $targ_h = 500; //Dimensions of cropped image
$jpeg_quality = 100; //Quality of cropped image
$src = "uploads/manual/src.jpg";
//defining handles for creating the crooped image
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
//Generating the image using co-ordinates represented by the Crop Box
imagecopyresampled($dst_r,$img_r,0,0,$_GET['x'],$_GET['y'],
$targ_w,$targ_h,$_GET['w'],$_GET['h']);
//saving the jpeg image after cropping
imagejpeg($dst_r,"uploads/manual/cropped/$photo",$jpeg_quality);
$article = $odf->setSegment('articles'); //Defining Segment articles( used in .odt file)
//image
$pic = "uploads/manual/cropped/".$photo;
if(!file_exists($pic))
{
$pic = "uploads/manual/image.gif";
}
$article->setImage('pic',$pic,4);
//name
if($mname==NULL)
$article->nameArticle(" ".$name." ".$fname." ".$lname);
else
$article->nameArticle(" ".$name." ".$fname." ".$mname." ".$lname);
//Institute/department
if($city==NULL)
$article->deptArticle($ins.", ".$state);
else
$article->deptArticle($ins.", ".$city);
$article->merge();
$odf->mergeSegment($article);
// We save the file
# Final ODT file.
$source_file = "odt/cert/$id.odt";
//$odf -> saveToDisk("odt/cert/$id.odt"); //Saving the odt file to directory
$odf -> saveToDisk($source_file); //Saving the odt file to directory
//Convert the odt format to pdf
//$source_file = "odt/cert/$id.odt";
$output_file = "/pdf/$id.pdf";
$get_current_dir= getcwd();
//$command = 'sudo unoconv -f pdf --output /var/www/html/Certificate/CGS/pdf/'.$source_file;
$command = 'unoconv -o ' .$get_current_dir.'/pdf/'.$id.'.pdf -f pdf ' .$source_file;
#$command = '/usr/bin/unoconv -o '.$output_file.' -f pdf '.$source_file;
$result = shell_exec($command);
echo $result;
echo '<html>
<head>
<link href="style/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="style/style.css" rel="stylesheet" media="screen">
</head>
<body>
<center>
<h1>Your Certificate has been Generated!</h1>
<form action="odt/cert/'.$id.'.odt">
<input class="btn btn-primary" type="submit" value="Download ODT">
</form>
<form action="pdf/'.$id.'.pdf">
<input class="btn btn-primary" type="submit" value="View/Download PDF">
</form>
<form action="option.php?var=manual" method = "GET">
<input type=hidden name=var value=manual>
<input class="btn btn-primary" type="submit" value="Generate Another Certificate">
</form>
<form action="index.html">
<input class="btn btn-primary" type="submit" value="Goto First Page">
</form>
</center>
</body>
</html>';
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Live Image Selector</title>
<h1><center>Crop Image</center></h1>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<script src="jcrop/jquery.min.js"></script>
<script src="jcrop/jquery.Jcrop.js"></script>
<link rel="stylesheet" href="jcrop/main.css" type="text/css" />
<link rel="stylesheet" href="jcrop/demos.css" type="text/css" />
<link rel="stylesheet" href="jcrop/jquery.Jcrop.css" type="text/css" />
<script type="text/javascript">
$(function(){
$('#cropbox').Jcrop({
boxWidth: 700,
boxHeight: 700,
aspectRatio: 1,
setSelect: [50, 0, 400,400],
minSize: [400,400],
allowSelect: false,
onSelect: updateCoords
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
</script>
<style type="text/css">
#target {
background-color: #ccc;
width: 500px;
height: 330px;
font-size: 24px;
display: block;
}
</style>
</head>
<body background="style/bck.jpg">
<div class="container">
<div class="row">
<div class="span12">
<div class="jc-demo-box">
<!-- This is the image we're attaching Jcrop to -->
<img src="uploads/manual/src.jpg" id="cropbox" />
<!-- This is the form that our event handler fills -->
<form action="manual.php" method="get" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="submit" value="Save & Generate Certificate" class="btn btn-large btn-inverse" /><!--..........CHANGE...-->
</form>
<p>
<b>Image Cropping Area.</b>Highlighted portion of the image will be selected.
</p>
</div>
</div>
</div>
</div>
</body>
</html>