forked from olawanlejoel/certificate-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
142 lines (119 loc) · 5.27 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Certificate Generator</title>
</head>
<body>
<center>
<br><br><br>
<h3>Certificate Generator</h3>
<br><br><br><br>
<form method="post" action="">
<div class="form-group col-sm-6">
<input type="text" name="name" class="form-control" id="name" placeholder="Enter Name Here...">
</div>
<div class="form-group col-sm-6">
<input type="text" name="occupation" class="form-control" id="organization" placeholder="Enter Organization Name Here...">
</div>
<button type="submit" name="generate" class="btn btn-primary">Generate</button>
</form>
<br>
<?php
if (isset($_POST['generate'])) {
$name = strtoupper($_POST['name']);
$name_len = strlen($_POST['name']);
$occupation = strtoupper($_POST['occupation']);
if ($occupation) {
$font_size_occupation = 10;
}
if ($name == "" || $occupation == "") {
echo
"
<div class='alert alert-danger col-sm-6' role='alert'>
Ensure you fill all the fields!
</div>
";
}else{
echo
"
<div class='alert alert-success col-sm-6' role='alert'>
Congratulations! $name on your excellent success.
</div>
";
//designed certificate picture
$image = "certi.png";
$createimage = imagecreatefrompng($image);
//this is going to be created once the generate button is clicked
$output = "certificate.png";
//then we make use of the imagecolorallocate inbuilt php function which i used to set color to the text we are displaying on the image in RGB format
$white = imagecolorallocate($createimage, 205, 245, 255);
$black = imagecolorallocate($createimage, 0, 0, 0);
//Then we make use of the angle since we will also make use of it when calling the imagettftext function below
$rotation = 0;
//we then set the x and y axis to fix the position of our text name
$origin_x = 200;
$origin_y=260;
//we then set the x and y axis to fix the position of our text occupation
$origin1_x = 120;
$origin1_y=90;
//we then set the differnet size range based on the lenght of the text which we have declared when we called values from the form
if($name_len<=7){
$font_size = 25;
$origin_x = 190;
}
elseif($name_len<=12){
$font_size = 30;
}
elseif($name_len<=15){
$font_size = 26;
}
elseif($name_len<=20){
$font_size = 18;
}
elseif($name_len<=22){
$font_size = 15;
}
elseif($name_len<=33){
$font_size=11;
}
else {
$font_size =10;
}
$certificate_text = $name;
//font directory for name
$drFont = dirname(__FILE__)."/developer.ttf";
// font directory for occupation name
$drFont1 = dirname(__FILE__)."/Gotham-black.otf";
//function to display name on certificate picture
$text1 = imagettftext($createimage, $font_size, $rotation, $origin_x, $origin_y, $black,$drFont, $certificate_text);
//function to display occupation name on certificate picture
$text2 = imagettftext($createimage, $font_size_occupation, $rotation, $origin1_x+2, $origin1_y, $black, $drFont1, $occupation);
imagepng($createimage,$output,3);
?>
<!-- this displays the image below -->
<img src="<?php echo $output; ?>">
<br>
<br>
<!-- this provides a download button -->
<a href="<?php echo $output; ?>" class="btn btn-success">Download My Internship Certificate</a>
<br><br>
<?php
}
}
?>
</center>
<footer>
<center><p>Built with ❤ by <a href="joel-new.netlify.app">Olawanle Joel</a></p></center>
</footer>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>