-
Notifications
You must be signed in to change notification settings - Fork 0
/
pngbar.php
49 lines (37 loc) · 1.32 KB
/
pngbar.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
<?php
function drawRating($rating, $max, $type) {
if($type == 0)
{
$image = imagecreatetruecolor(102,15);
$back = ImageColorAllocate($image,250,250,250);
$border = ImageColorAllocate($image,0,0,0);
$fill = ImageColorAllocate($image,0,235,0);
ImageFilledRectangle($image,0,0,101,14,$back);
ImageFilledRectangle($image,1,1,$rating/$max * 100,14,$fill);
ImageRectangle($image,0,0,101,14,$border);
$textcolor = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 35, 0, ($rating/$max * 100).'%', $textcolor);
}
else
{
if($rating > $max) $rating = $max;
$image = imagecreatetruecolor(10 * ($rating + 2) + 2,15);
$back = ImageColorAllocate($image,250,250,250);
$border = ImageColorAllocate($image,0,0,0);
$fill = ImageColorAllocate($image,235,0,0);
ImageFilledRectangle($image,0,0,10 * ($rating + 2) + 1,14,$back);
ImageFilledRectangle($image,1,1,10 * $rating,14,$fill);
ImageRectangle($image,0,0,10 * ($rating ) + 1,14,$border);
$textcolor = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 10 * ($rating + 1), 0, $rating, $textcolor);
}
imagepng($image);
imagedestroy($image);
}
Header("Content-type: image/png");
$rating = (isset($_GET['rating'])) ? $_GET['rating'] : 0;
if($_GET['type'] == 'priority')
drawRating($rating, 10, 1);
else
drawRating($rating, 100, 0);
?>