4 +-----------------------------------------------------------------------+
5 | program/bin/quotaimg.php |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Create a GIF image showing the mailbox quot as bar |
14 +-----------------------------------------------------------------------+
15 | Author: Brett Patterson <brett2@umbc.edu> |
16 +-----------------------------------------------------------------------+
22 $used = ((isset($_GET['u']) && !empty($_GET['u'])) || $_GET['u']=='0')?(int)$_GET['u']:'??';
23 $quota = ((isset($_GET['q']) && !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??';
24 $width = empty($_GET['w']) ? 100 : (int)$_GET['w'];
25 $height = empty($_GET['h']) ? 14 : (int)$_GET['h'];
27 function genQuota($used, $total, $width, $height)
32 * Modify the following few elements to change the display of the image.
33 * Modifiable attributes are:
34 * bool border :: Defines whether you want to show a border around it or not.
35 * bool unknown :: Leave default; Defines whether quota is "unknown"
37 * int height :: Defines height of the image
38 * int width :: Defines width of the image
39 * int font :: Changes the font size & font used in the GD library.
40 * Available values are from 1 to 5.
41 * int padding :: Changes the offset (in pixels) from the top of the image to
42 * where the top of the text will be aligned. User greater than
43 * 0 to ensure text is off the border.
44 * array limit :: Holds the integer values of in an associative array as to what
45 * defines the upper and lower levels for quota display.
46 * High - Quota is nearing capacity.
47 * Mid - Quota is around the middle
48 * Low - Currently not used.
49 * array color :: An associative array of strings of comma separated values (R,G,B)
50 * for use in color creation. Define the RGB values you'd like to
51 * use. A list of colors (and their RGB values) can be found here:
52 * http://www.december.com/html/spec/colorcodes.html
66 $color['fill']['high'] = '215, 13, 13'; // Near quota fill color
67 $color['fill']['mid'] = '126, 192, 238';// Mid-area of quota fill color
68 $color['fill']['low'] = '147, 225, 100'; // Far from quota fill color
71 $color['bg']['OL'] = '215, 13, 13'; // Over limit bbackground
72 $color['bg']['Unknown'] = '238, 99, 99';// Unknown background
73 $color['bg']['quota'] = '255, 255, 255';// Normal quota background
76 $color['border'] = '0, 0, 0';
77 $color['text'] = '102, 102, 102';
80 /****************************
81 ***** DO NOT EDIT BELOW HERE *****
82 ****************************/
84 if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total))
87 if (strpos($used, '?')!==false || strpos($total, '?')!==false && $used != 0)
90 $im = imagecreate($width, $height);
94 list($r, $g, $b) = explode(',', $color['border']);
95 $borderc = imagecolorallocate($im, $r, $g, $b);
96 imageline($im, 0, 0, $width, 0, $borderc);
97 imageline($im, 0, $height-$border, 0, 0, $borderc);
98 imageline($im, $width-1, 0, $width-$border, $height, $borderc);
99 imageline($im, $width, $height-$border, 0, $height-$border, $borderc);
102 list($r, $g, $b) = explode(',', $color['text']);
103 $text = imagecolorallocate($im, $r, $g, $b);
107 list($r, $g, $b) = explode(',', $color['bg']['Unknown']);
108 $background = imagecolorallocate($im, $r, $g, $b);
109 imagefilledrectangle($im, 0, 0, $width, $height, $background);
112 $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
113 imagestring($im, $font, $mid, $padding, $string, $text);
115 else if ($used > $total)
117 list($r, $g, $b) = explode(',', $color['bg']['OL']);
118 $background = imagecolorallocate($im, $r, $g, $b);
119 imagefilledrectangle($im, 0, 0, $width, $height, $background);
121 $string = 'Over Limit';
122 $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
123 imagestring($im, $font, $mid, $padding, $string, $text);
127 list($r, $g, $b) = explode(',', $color['bg']['quota']);
128 $background = imagecolorallocate($im, $r, $b, $g);
129 imagefilledrectangle($im, 0, 0, $width, $height, $background);
131 $quota = ($used==0)?0:(round($used/$total, 2)*100);
133 if ($quota >= $limit['high'])
135 list($r, $g, $b) = explode(',', $color['fill']['high']);
136 $fill = imagecolorallocate($im, $r, $g, $b);
138 elseif($quota >= $limit['mid'])
140 list($r, $g, $b) = explode(',', $color['fill']['mid']);
141 $fill = imagecolorallocate($im, $r, $g, $b);
143 else // if($quota >= $limit['low'])
145 list($r, $g, $b) = explode(',', $color['fill']['low']);
146 $fill = imagecolorallocate($im, $r, $g, $b);
149 $quota_width = $quota / 100 * $width;
150 imagefilledrectangle($im, $border, 0, $quota, $height-2*$border, $fill);
152 $string = $quota.'%';
153 $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
154 imagestring($im, $font, $mid, $padding, $string, $text); // Print percent in black
157 header('Content-Type: image/gif');
158 header("Expires: ".gmdate("D, d M Y H:i:s", mktime()+86400)." GMT");
159 header("Cache-Control: ");
167 genQuota($used, $quota, $width, $height);