Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Problem z generatorem
Forum PHP.pl > Forum > Przedszkole
Kei92
Witam mam problem z generatorem zdjęć . Skrypt działa , ale tworzy brzydkie biała tło co na mojej stronie nie pasuje . Chciałbym aby skrypt tworzył przezroczyste tło , ale nie wiem jak . Próbowałem już użyć imagesavealpha() , ale coś mi nie działa sadsmiley02.gif
Oto kod generatora :
  1. <?php
  2.  
  3.  
  4. define('PROGRESS_BAR', true);
  5.  
  6. // Pobranie konfiguracji
  7. include './config.php';
  8. // Pobranie zawartości progress bara
  9. include './data.php';
  10. // Pobranie tablicy języka
  11. include './lang_progress_bar.php';
  12.  
  13. // Sorotwanie
  14. if($config['progress_bar']['sort_by'] === 0 || $config['progress_bar']['sort_by'] === 1 AND $config['progress_bar']['sort_type'] == 'asc' || $config['progress_bar']['sort_type'] == 'desc')
  15. {
  16. foreach($progress_bar as $key => $value)
  17. {
  18. $tmp['column'][$key] = $value[$config['progress_bar']['sort_by']];
  19. }
  20.  
  21. array_multisort($tmp['column'], ($config['progress_bar']['sort_type'] == 'asc' ? SORT_ASC : SORT_DESC), $progress_bar);
  22. }
  23.  
  24. $tmp['how'] = count($progress_bar);
  25. // Tworzenie obrazka
  26. $img = imagecreate($config['progress_bar']['width'], ($tmp['how'] == 0 ? 1 : $tmp['how']) * $config['progress_bar']['height']);
  27. // Tworzenie kolorów
  28. $tmp['color']['dark_red'] = imagecolorallocate($img, 200, 0, 0);
  29. $tmp['color']['red'] = imagecolorallocate($img, 255, 0, 0);
  30. $tmp['color']['orange'] = imagecolorallocate($img, 255, 200, 0);
  31. $tmp['color']['green'] = imagecolorallocate($img, 169, 211, 41);
  32. $tmp['color']['dark_green'] = imagecolorallocate($img, 128, 160, 32);
  33. $tmp['color']['black'] = imagecolorallocate($img, 255, 255, 255);
  34. $tmp['color']['white'] = imagecolorallocate($img, 255, 255, 255);
  35. $tmp['color']['nic'] = imagecolorallocatealpha($img, 255, 255, 255, 100);
  36. // Tło
  37. imagefill($img, 0, 0, $tmp['color']['nic']);
  38. // Rozmiary czcionek
  39. $tmp['font']['width'] = imagefontwidth($config['progress_bar']['font_size']);
  40. $tmp['font']['height'] = imagefontheight($config['progress_bar']['font_size']);
  41.  
  42. if($tmp['how'] > 0)
  43. {
  44. for($h = 0; $h < $tmp['how']; ++$h)
  45. {
  46. if(strlen($progress_bar[$h][0]) > 27)
  47. {
  48. $progress_bar[$h][0] = substr($progress_bar[$h][0], 0, 24).'...';
  49. }
  50.  
  51. if(!is_int($progress_bar[$h][1]) || $progress_bar[$h][1] < 0 || $progress_bar[$h][0] > 100)
  52. {
  53. $progress_bar[$h][1] = 0;
  54. }
  55.  
  56. // Pozycja procentów
  57. if($config['progress_bar']['right_aligned_procent'] == true)
  58. {
  59. $tmp['procent_length'] = strlen($progress_bar[$h][1]);
  60.  
  61. if($tmp['procent_length'] == 1)
  62. {
  63. $tmp['procent_position'] = 170 + 2 * $tmp['font']['width'];
  64. }
  65. else if($tmp['procent_length'] == 2)
  66. {
  67. $tmp['procent_position'] = 170 + $tmp['font']['width'];
  68. }
  69. else
  70. {
  71. $tmp['procent_position'] = 170;
  72. }
  73. }
  74. else
  75. {
  76. $tmp['procent_position'] = 170;
  77. }
  78.  
  79. // Obliczanie y1, y2
  80. $tmp['y'][0] = 20 * $h;
  81. $tmp['y'][1] = 20 * $h + $tmp['font']['height'];
  82. // Nazwa projektu
  83. imagestring($img, $config['progress_bar']['font_size'], 5, $h * 20 + 2, $progress_bar[$h][0], $tmp['color']['black']);
  84. // Postęp
  85. imagestring($img, $config['progress_bar']['font_size'], $tmp['procent_position'], $h * 20 + 2, $progress_bar[$h][1].'%', $tmp['color']['black']);
  86.  
  87. // Wybieranie koloru dla paska postępu
  88. if($progress_bar[$h][1] > 85)
  89. {
  90. $tmp['color']['bar'] = $tmp['color']['dark_green'];
  91. }
  92. else if($progress_bar[$h][1] > 70)
  93. {
  94. $tmp['color']['bar'] = $tmp['color']['green'];
  95. }
  96. else if($progress_bar[$h][1] > 40)
  97. {
  98. $tmp['color']['bar'] = $tmp['color']['orange'];
  99. }
  100. else if($progress_bar[$h][1] > 10)
  101. {
  102. $tmp['color']['bar'] = $tmp['color']['red'];
  103. }
  104. else
  105. {
  106. $tmp['color']['bar'] = $tmp['color']['dark_red'];
  107. }
  108.  
  109. // Pasek postępu
  110. if($progress_bar[$h][1] > 0)
  111. {
  112. imagefilledrectangle($img, 201, $tmp['y'][0] + 3, 201 + floor($progress_bar[$h][1] * 2.95), $tmp['y'][1], $tmp['color']['bar']);
  113. }
  114.  
  115. // Lewa kreska postępu
  116. imagefilledrectangle($img, 200, $tmp['y'][0] + 3, 200, $tmp['y'][1], $tmp['color']['bar']);
  117. // Prawa kreska postępu
  118. imagefilledrectangle($img, 495, $tmp['y'][0] + 3, 496, $tmp['y'][1], $tmp['color']['bar']);
  119.  
  120. // Napisy na progress barze
  121. if($config['progress_bar']['inscriptions_on_the_bar'] === true)
  122. {
  123. if($progress_bar[$h][1] == 100)
  124. {
  125. $tmp['inscription'] = $lang['progress_bar']['been_completed'];
  126. }
  127. else if($progress_bar[$h][1] > 95)
  128. {
  129. $tmp['inscription'] = $lang['progress_bar']['its_almost_done'];
  130. }
  131. else
  132. {
  133. $tmp['inscription'] = '';
  134. }
  135.  
  136. imagestring($img, 2, 210, $tmp['y'][0] + 1, $tmp['inscription'], $tmp['color']['black']);
  137. }
  138. }
  139. }
  140. else
  141. {
  142. $tmp['font']['width'] *= strlen($lang['progress_bar']['we_currently_do_not_work_on_any_project']);
  143. $tmp['position']['center'] = ceil(($config['progress_bar']['width'] - $tmp['font']['width']) / 2);
  144. $tmp['position']['middle'] = ceil(($config['progress_bar']['height'] - $tmp['font']['height']) / 2) - 1;
  145. // Tworzenie wyśrodkowanego napisu mówiącego o braku projektów
  146. imagestring($img, $config['progress_bar']['font_size'], $tmp['position']['center'], $tmp['position']['middle'], $lang['progress_bar']['we_currently_do_not_work_on_any_project'], $tmp['color']['black']);
  147. }
  148.  
  149. header('Content-type: image/png');
  150. # header('Expires: Mon, 26 Jul 1997 0500 GMT');
  151. # header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  152. # header('Cache-Control: no-store, no-cache, must-revalidate');
  153. # header('Cache-Control: post-check=0, pre-check=0', false);
  154. # header('Pragma: no-cache');
  155.  
  156. imagepng($img);
  157. imagedestroy($img);
  158. ?>

I postawie coś takiego :

nie jest to idealnie przezroczysta . Pozostaje taka biała otoczka , czy ktoś może mi pomóc specool.gif
redeemer
http://php.net/manual/pl/function.imagecol...locatealpha.php
Zwróc uwagę na parametr $alpha
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-2025 Invision Power Services, Inc.