-
Notifications
You must be signed in to change notification settings - Fork 0
/
createCard.php
121 lines (103 loc) · 3.06 KB
/
createCard.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
<?php
//require('common.php');
require('phpqrcode/qrlib.php');
$template_image = 'images/MADCREDT.png';
$im = ImageCreateFromPng($template_image);
$black = imagecolorallocate($im, 0, 0, 0);
$madRed = imagecolorallocate($im, 237, 24, 73);
$phoneNumber = (string)$_POST['phoneNumber'];
$phoneNumberAppended = checkCode($phoneNumber);
ImageTtfText($im, 35, 0, 15, 323, $madRed, "fonts/BebasNeue-webfont.ttf", $_POST['Name']); // Name
/*Parameters
1. Image Vector Variable
2. Font Size
3. Inclination (degrees)
4. X Pos
5. Y Pos
6. Color Code
7. Fonts
8. String to be placed.
*/
function appendZeros($string,$len){
$nZ = 6-$len;
//echo $nZ;
$zeros="";
for($i=0;$i<$nZ;$i++){
$zeros.="0";
}
$final = $zeros.$string;
return $final;
}
function checkCode($phone){
$len = strlen($phone);
$phoneWithCode = "+91-";
if($len>10){
for($i=($len-10);$i<$len;$i++){
$phoneWithCode.=$phone[$i];
}
}
else{
$phoneWithCode.=$phone;
}
return $phoneWithCode;
}
$length = strlen($_POST['userID']);
$link = 'www.makeadiff.in/volunteer/'.$_POST['userID'];
$frame = QRcode::text($link, false, QR_ECLEVEL_L, 4, 0);
$qrcode = get_qrcode($frame);
$idNumber = (string)$_POST['userID'];
$idSixLength = appendZeros($idNumber,$length);
//echo $idSixLength;
ImageTtfText($im, 13, 0, 15, 343, $black, "fonts/BebasNeue-webfont.ttf", $_POST['Post']);
ImageTtfText($im, 15, 0, 48, 382, $black, "fonts/univers.ttf",$phoneNumberAppended );
ImageTtfText($im, 15, 0, 48, 410, $black, "fonts/univers.ttf", $_POST['Email']);
ImageTtfText($im, 13, 0, 637, 324, $madRed, "fonts/BebasNeue-webfont.ttf", "MAD ID : ");
ImageTtfText($im, 13, 0, 682, 324, $madRed, "fonts/BebasNeue-webfont.ttf", $idSixLength);
ImageTtfText($im, 15, 0, 48, 432, $black, "fonts/univers.ttf", $link);
imagecopyresampled($im, $qrcode, 637, 336, 0, 0, 90, 90, 100, 100);
/*
Parameters
1. Final Image
2. Sampled Image
3. Start X
4. Start Y
5. Source X Point
6. Source Y Point
7. Image Width
8. Image Height
9. Source Width
10. Source Height
*/
header('Content-Disposition: attachment; filename='.$_POST['Name'].' Card.png');
header('Pragma: no-cache');
imagepng($im);
imagedestroy($im);
function get_qrcode($frame) {
$outerFrame = 0;
$pixelPerPoint = 4;
$h = count($frame);
$w = strlen($frame[0]);
$imgW = $w + 2 * $outerFrame;
$imgH = $h + 2 * $outerFrame;
$base_image = imagecreate($imgW, $imgH);
$col[0] = imagecolorallocate($base_image,255,255,255); // BG, white
$col[1] = imagecolorallocate($base_image,0,0,0); // FG,
imagefill($base_image, 0, 0, $col[0]);
for($y=0; $y<$h; $y++) {
for($x=0; $x<$w; $x++) {
if ($frame[$y][$x] == '1') {
imagesetpixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]);
}
}
}
// saving to file
$target_image = imagecreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
imagecopyresized(
$target_image,
$base_image,
0, 0, 0, 0,
$imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH
);
return $target_image;
}
?>