-
Notifications
You must be signed in to change notification settings - Fork 1
/
reward.php
64 lines (45 loc) · 1.37 KB
/
reward.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
<?php
$result = (int) (isset($_GET['percentage'])) ? $_GET['percentage'] : 0;
$size = (int) (isset($_GET['size'])) ? $_GET['size'] : 50;
$image = 'graphics/_600-20.png';
if($result < 0){
$result = 0;
}
if($result > 0 && $result <= 25){
$image = 'graphics/20-40.png';
} else if($result > 25 && $result <= 50) {
$image = 'graphics/40-60.png';
} else if($result > 50 && $result <= 75) {
$image = 'graphics/60-80.png';
} else if($result > 75 && $result <= 100){
$image = 'graphics/80-100.png';
} else if($result > 100){
$result = -1000;
$image = 'graphics/fail.png';
}
$gdimage = imagecreatefrompng($image);
$font = './fonts/Monofett.ttf';
$text = sprintf('%s%%', $result);
$fontsize = 110;
$textbox = imagettfbbox($fontsize, 0, $font, $text);
$x = ceil((530 - $textbox[2]) / 2);
$colour = imagecolorallocate($gdimage, 0, 0, 0);
imagettftext($gdimage, $fontsize, 0, $x, 117, $colour, $font, $text);
// Resize image
if($size < 50){
$size = 50;
} else if($size > 100){
$size = 100;
}
if($size < 100) {
$size = ($size / 100);
list($width, $height) = getimagesize($image);
$newwidth = $width * $size;
$newheight = $height * $size;
$newimage = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($newimage, $gdimage, 0,0,0,0, $newwidth, $newheight, $width, $height);
$gdimage = $newimage;
}
header('Content-Type: image/png');
imagepng($gdimage);
imagedestroy($gdimage);