Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: gd progressbar
Forum PHP.pl > Forum > Gotowe rozwiązania
GrayHat
witam. potrzebuje skryptu kreslacego progressbar w gd...
tiraeth
  1. <?php
  2. # procent wykonania (mozna pobierac z formularza)
  3.  $percent = 45;
  4.  
  5. # szerokosc paska w pikselach
  6.  $progress['width'] = 100;
  7.  
  8. # wysokosc paska w pikselach
  9.  $progress['height'] = 13;
  10.  
  11. # kolor tla paska
  12.  $progress['color'] = 'FFFFFF';
  13.  
  14. # kolor paska
  15. # mozna zrobic dynamiczny... musisz sie pobawic :)
  16.  $progress['line'] = 'FF0000';
  17.  
  18. # kolor ramki paska
  19.  $progress['border'] = '888888';
  20.  
  21. # kolor czcionki
  22.  $progress['font'] = '000000';
  23.  
  24. # modyfikujemy kolory na czerwony, zielony i niebieski
  25.  $color_r = hexdec(substr($progress['color'], 0, 2));
  26.  $color_g = hexdec(substr($progress['color'], 2, 2));
  27.  $color_b = hexdec(substr($progress['color'], 4, 2));
  28.  $border_r = hexdec(substr($progress['border'], 0, 2));
  29.  $border_g = hexdec(substr($progress['border'], 2, 2));
  30.  $border_b = hexdec(substr($progress['border'], 4, 2));
  31.  $line_r = hexdec(substr($progress['line'], 0, 2));
  32.  $line_g = hexdec(substr($progress['line'], 2, 2));
  33.  $line_b = hexdec(substr($progress['line'], 4, 2));
  34.  $font_r = hexdec(substr($progress['font'], 0, 2));
  35.  $font_g = hexdec(substr($progress['font'], 2, 2));
  36.  $font_b = hexdec(substr($progress['font'], 4, 2));
  37.  
  38.  
  39. $img = imagecreatetruecolor($progress['width'], $progress['height'])
  40.  or die('Nie można utworzyć obrazu GD');
  41.  
  42. # robimy ramke
  43. $border_color = imagecolorallocate($img, $border_r, $border_g, $border_b);
  44. $fill_color = imagecolorallocate($img, $color_r, $color_g, $color_b);
  45. $font_color = imagecolorallocate($img, $font_r, $font_g, $font_b);
  46.  
  47. # kolorujemy caly pasek
  48. imagefill($img, 0, 0, $fill_color);
  49.  
  50. $line_color = imagecolorallocate($img, $line_r, $line_g, $line_b);
  51. $width = $progress['width']; $width--;
  52. $height = $progress['height']; $height--;
  53.  
  54. imagerectangle($img, 0, 0, $width, $height, $border_color);
  55.  
  56. $new_x = round(($percent*$progress['width'])/100);
  57.  #usuwamy jeden piksel w szerokosci na ramke
  58. $new_x-= 3;
  59.  
  60. $new_y = $progress['height'];
  61.  # j/w
  62. $new_y-= 3;
  63.  
  64. imagefilledrectangle($img, 2, 2, $new_x, $new_y, $line_color);
  65.  
  66. $font_x = $progress['width']/2;
  67. $font_x-= strlen($percent)*3;
  68. $font_x-= 3;
  69. $font_y = $progress['height']/2;
  70. $font_y-= 3;
  71.  
  72. imagestring($img, 1, $font_x, $font_y, $percent.'%', $font_color);
  73.  
  74. header(&#092;"Content-type: image/png\");
  75. imagepng($img);
  76. imagedestroy($img);
  77. ?>


Właśnie napisałem smile.gif 45 minut roboty ale jest tongue.gif Jeżeli chodzi o napis to można go usunać albo zastąpić imagettftext, który daje ładniejszy wygląd tongue.gif

pozdro!
WebKing
Super skrypt jesteś Rkingsmiley.png
bim2
  1. <?php
  2. # kolor paska
  3. # mozna zrobic dynamiczny... musisz sie pobawic :) (już jest haha.gif)
  4. $colors = array('00FF22','119F09','FDFF00','FFA200','FF0000','AF2D00');
  5. if($percent < 10)
  6.  $progress['line'] = $colors[5];
  7. elseif($percent >= 10 AND $percent < 30)
  8.  $progress['line'] = $colors[4];
  9. elseif($percent >= 30 AND $percent < 50)
  10.  $progress['line'] = $colors[3];
  11. elseif($percent >= 50 AND $percent < 70)
  12.  $progress['line'] = $colors[2];
  13. elseif($percent >= 70 AND $percent < 90)
  14.  $progress['line'] = $colors[1];
  15. elseif($percent >= 90 AND $percent < 101)
  16.  $progress['line'] = $colors[0];
  17. ?>

Nudziło mi się winksmiley.jpg
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.