Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> gd progressbar
GrayHat
post 18.05.2005, 23:42:11
Post #1





Grupa: Zarejestrowani
Postów: 566
Pomógł: 18
Dołączył: 23.08.2003
Skąd: Łomża

Ostrzeżenie: (0%)
-----


witam. potrzebuje skryptu kreslacego progressbar w gd...


--------------------
*Note: No animals were killed durning the construction of this post.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
tiraeth
post 19.05.2005, 07:47:29
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


  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!
Go to the top of the page
+Quote Post
WebKing
post 24.08.2007, 20:11:51
Post #3





Grupa: Zarejestrowani
Postów: 219
Pomógł: 16
Dołączył: 16.07.2007

Ostrzeżenie: (0%)
-----


Super skrypt jesteś Rkingsmiley.png
Go to the top of the page
+Quote Post
bim2
post 28.08.2007, 15:46:07
Post #4





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

Ostrzeżenie: (0%)
-----


  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


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 07:43