Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Obrazek GD w pętli while
fredzio90
post
Post #1





Grupa: Zarejestrowani
Postów: 251
Pomógł: 0
Dołączył: 19.02.2007

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


otóż przewertowałem forum i znalazłem kod który pokazuje pasek postępu.. chciałem go przystosować do MySQL i prubuje tak:

cała funkcja wygląda tak:

  1. <?php
  2. function progres_bar($procent = '', $szer=100, $wys=13, $kol_font='000000', $kol_obr='888888', $kol_pas='FFFFFF')
  3. {
  4. $colors = array('00FF22', '119F09', 'FDFF00', 'FFA200', 'FF0000', 'AF2D00');
  5. if ($procent < 10)
  6. $dynamika = $colors[5];
  7. elseif ($procent >= 10 and $procent < 30)
  8. $dynamika = $colors[4];
  9. elseif ($procent >= 30 and $procent < 50)
  10. $dynamika = $colors[3];
  11. elseif ($procent >= 50 and $procent < 70)
  12. $dynamika = $colors[2];
  13. elseif ($procent >= 70 and $procent < 90)
  14. $dynamika = $colors[1];
  15. elseif ($procent >= 90 and $procent < 101)
  16. $dynamika = $colors[0];
  17. $color_r = hexdec(substr($kol_pas, 0, 2));
  18. $color_g = hexdec(substr($kol_pas, 2, 2));
  19. $color_b = hexdec(substr($kol_pas, 4, 2));
  20. $border_r = hexdec(substr($kol_obr, 0, 2));
  21. $border_g = hexdec(substr($kol_obr, 2, 2));
  22. $border_b = hexdec(substr($kol_obr, 4, 2));
  23. $line_r = hexdec(substr($dynamika, 0, 2));
  24. $line_g = hexdec(substr($dynamika, 2, 2));
  25. $line_b = hexdec(substr($dynamika, 4, 2));
  26. $font_r = hexdec(substr($kol_font, 0, 2));
  27. $font_g = hexdec(substr($kol_font, 2, 2));
  28. $font_b = hexdec(substr($kol_font, 4, 2));
  29. $img = imagecreatetruecolor($szer, $wys) or die('Nie można utworzyć obrazu GD');
  30. $border_color = imagecolorallocate($img, $border_r, $border_g, $border_b);
  31. $fill_color = imagecolorallocate($img, $color_r, $color_g, $color_b);
  32. $font_color = imagecolorallocate($img, $font_r, $font_g, $font_b);
  33. imagefill($img, 0, 0, $fill_color);
  34. $line_color = imagecolorallocate($img, $line_r, $line_g, $line_b);
  35. $width = $szer;
  36. $width--;
  37. $height = $wys;
  38. $height--;
  39. imagerectangle($img, 0, 0, $width, $height, $border_color);
  40. $new_x = round(($procent * $szer) / 100);
  41. $new_x -= 3;
  42. $new_y = $wys;
  43. $new_y -= 3;
  44. imagefilledrectangle($img, 2, 2, $new_x, $new_y, $line_color);
  45. $font_x = $szer / 2;
  46. $font_x -= strlen($procent) * 3;
  47. $font_x -= 3;
  48. $font_y = $wys / 2;
  49. $font_y -= 3;
  50. imagestring($img, 1, $font_x, $font_y, $procent . '%', $font_color);
  51. header("Content-type: image/png");
  52. imagepng($img);
  53. imagedestroy($img);
  54. }
  55. ?>


i w pętli while przy odczytywaniu wszyskich warunków z bazy:

  1. <?php
  2. while(warunek) {
  3. <td bgcolor="'.$bg.'" class="uni_01">'.progres_bar($r[postep], '100', '13', '000000', '888888', 'FFFFFF').'</td>
  4. }
  5. ?>


pokazuje:

Cytat
Obrazek "http://localhost/jpnew/projekty.php?cmd=skonczone" nie może zostać wyświetlony, ponieważ zawiera błędy.


a jak bym wywołać funkcje tak:

  1. <?php
  2. progres_bar('45', '100', '13', '000000', '888888', 'FFFFFF');
  3. ?>


to żadnych błędów nie wywala
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 23.08.2025 - 05:57