-
Notifications
You must be signed in to change notification settings - Fork 1
/
genratecard.php
164 lines (121 loc) · 4.9 KB
/
genratecard.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
<?php
include "phpqrcode-master/qrlib.php";
// database conectivity
$hostname="localhost";
$password="root";
$username="root";
$database="businesscard";
$conn = new mysqli($hostname, $username, $password, $database);
if (!$conn) {
die($conn->connect_error);
}else{
// echo "connected successfuly";
}
// form data
$username=$_POST['username'];
$email=$_POST['email'];
$contactno=$_POST['contactNo'];
$cardimagepath="./cards"."/$username".".jpg";
// image uploader
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
// echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
// echo "File is not an image.";
// $uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
// echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
// echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
// echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
// echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
// echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
// echo "Sorry, there was an error uploading your file.";
}
}
function create_image($imagepath,$username,$email,$contactno,$connection){
$im = @imagecreate(336, 192) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 0, 0, 255); // two top box colors of the card
// deatils of the
$phonetextcolor = imagecolorallocate($im, 255, 255, 255);
$nametextcolor = imagecolorallocate($im, 0, 0, 0);
$emailtextcolor = imagecolorallocate($im, 0, 0, 0);
$font='./fonts/tomnr.ttf';
$overlayImage = imagecreatefromjpeg($imagepath);// image of the user
imagefilledrectangle ($im, 0, 140, 336,192, $blue);
imagefilledrectangle ($im, 0, 0, 336,10, $blue);
imagefilledrectangle ($im, 0, 0, 336,10, $blue);
imagestring($im, 7, 5, 160,$contactno, $phonetextcolor);
imagettftext($im, 20, 0, 130, 60, $nametextcolor, $font, $username);
imagestring($im, 7,130, 70, $email, $emailtextcolor);
imagecopyresampled($im, $overlayImage, 10, 20, 0, 0, 100,100,imagesx($overlayImage),imagesy($overlayImage)); // final image
QRcode::png("http://www.sitepoint.com", "./cards/$username.png", "L", 4, 4); // genrating qr code link for downloading
imagejpeg($im,"./cards/$username.jpg");// creating the final image
imagedestroy($im); // destroy the image
$cardpath="./cards/$username.jpg";
$qrcardpath="./cards/$username.png";
$query= "INSERT INTO `cards` (`id`, `name`, `email`, `telephone`,`cardpath`,`qrcardpath`) VALUES (NULL, '$username', '$email', '$contactno','$cardpath','$qrcardpath')";
$result = $connection->query($query);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./bootstrap-3.3.7/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="./style.css">
<title>Document</title>
</head>
<body class="body">
<div class="container">
<div class=" col-md-12 image-container">
<div class="col-md-4"></div>
<div class="col-md-4 well">
<?php
create_image($target_file,$username,$email,$contactno,$conn);
print"<a download='$username.jpg' href='./cards/$username.jpg' title='ImageName'>";
print "<img src='./cards/$username.jpg'>";
print"</a>";
?>
<?php
print" <div class='download-button col-md-12'>Click on the image to download</div>";
print "<img alt='ImageName' src='./cards/$username.png'>";
?>
</div>
<div class="col-md-4">
</div>
</div>
</div>
<script src="./jquery-3.3.1.min.js"></script>
<script src="./bootstrap-3.3.7/dist/js/bootstrap.min.js"></script>
</body>
</html>