Code

- Updated fro new Debian upload
[gosa.git] / html / progress.php
1 <?php
2 /*
3   This code is part of GOsa (https://gosa.gonicus.de)
4   Copyright (C) 2003  Cajus Pollmeier
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2 of the License, or
9   (at your option) any later version.
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
21   /* Check for parameter completenes */
22   if (!isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['p'])){
23     die ("Missing parameters!");
24   }
25   if (!is_numeric($_GET['x']) || !is_numeric($_GET['y'])){
26     die ("Parameters must be numeric!");
27   }
29   $p= (int)($_GET['p']);
30   $x= (int)($_GET['x']);
31   $y= (int)($_GET['y']);
33   /* Check percentage */
34   if ($p < 0){
35     $p= 0;
36   } elseif ($p > 100){
37     $p= 100;
38   }
39   $p= intval ($p);
41   /* Check dimensions */
42   if ($x < 3 || $x > 1000){
43     $x= 180;
44   }
45   if ($y < 3 || $y > 700){
46     $y= 20;
47   }
49   $x_matches= FALSE;
50   $y_matches= FALSE;
51   foreach (array(7,6,5,4,3,2,1,0) as $font){
52     $fx= ImageFontWidth($font) * strlen("$p%");
53     $fy= ImageFontHeight($font);
55     /* Look if font size matches image size */
56     if ($fx < ($x-2)){
57       $x_matches= TRUE;
58     }
59     if ($fy < ($y-2)){
60       $y_matches= TRUE;
61     }
62     if ($x_matches && $y_matches){
63       break;
64     }
65   }
67   /* Draw image in GD image stream */
68   $im = @imagecreate ($x, $y)
69       or die ("Cannot Initialize new GD image stream");
71   /* Set colors */
72   $bg_color= imagecolorallocate ($im, 255, 255, 255);
73   $br_color= imagecolorallocate ($im, 0,0,0);
74   $fi_color= imagecolorallocate ($im, 0,0,180);
75   $tx_color= imagecolorallocate ($im, 240, 10, 90);
77   /* Draw progress bar */
78   imagerectangle ($im, 0, 0, $x-1, $y-1, $br_color);
79   imagefilledrectangle ($im, 1, 1, (($x - 2) * $p / 100),
80                                      $y - 2, $fi_color);
82   /* Is font to big for progress bar? */
83   if ($font != 0){
84     imagestring ($im, $font, ($x - $fx) / 2, ($y - $fy) / 2, "$p%", $tx_color);
85   }
87   /* Finally draw the image and remove context */
88   header ("Content-type: image/png");
89   imagepng ($im);
90   imagedestroy ($im);
91 ?>