Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Generowanie tła za pomocą php, następnie pisanie po nim
Michael2318
post
Post #1





Grupa: Zarejestrowani
Postów: 651
Pomógł: 116
Dołączył: 3.06.2012
Skąd: Lędziny

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


Generuje sobie tak tło i potem na nim rysuje linie oraz pisze tekst:

  1. $background = 'images/anti_robotic_reg/kapczh/anti_robotic_reg.png';
  2. $cap = imagecreatefrompng($background);
  3. $color = imagecolorallocate($cap, 0, 0, 0);


Jednak postanowiłem załadować tło funkcją PHP no bo po co marnować czas na ładowanie obrazka, skoro to prostokąt niebieski... Zrobiłem coś takiego:


  1. $background = ImageCreate(195,63);
  2. $bg = ImageColorAllocate($background,239,239,255);
  3. $cap = imagePng($background);
  4. $color = imagecolorallocate($cap, 0, 0, 0);


Problem w tym, że teraz zmienna $cap nie jest obsługiwana, głównie przez funkcje imagecolorallocate() i ni cholery nie wiem czemu. Przypuszczam, że przez to, iż w zmiennej $cap kryje się funkcja imagePng(), zamiast wcześniej użytej - createimagefrompng(). Tylko dlaczego ta funkcja jest nieobsługiwana ? Jakiś zamiennik może?
Go to the top of the page
+Quote Post
!*!
post
Post #2





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


A sprawdziłeś jak działają te funkcje? imagepng imagecreatefrompng Przekazujesz dane do $background, ale na ich podstawie nic nie tworzysz.

Ten post edytował !*! 27.12.2012, 18:58:31
Go to the top of the page
+Quote Post
Michael2318
post
Post #3





Grupa: Zarejestrowani
Postów: 651
Pomógł: 116
Dołączył: 3.06.2012
Skąd: Lędziny

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


Tworzę. Stary kod, pobierający tło z pliku:

  1. $gen_reg_key = $key;
  2. header('Content-Type: image/png');
  3.  
  4. $background = 'images/anti_robotic_reg/kapczh/anti_robotic_reg.png';
  5. $fonts = glob('images/anti_robotic_reg/kapczh/*.TTF');
  6. $num_letters = 5;
  7. $cap = imagecreatefrompng($background);
  8. $lines = imagecolorallocate($cap, 0, 0, 0);
  9. $color = imagecolorallocate($cap, 0, 0, 0);
  10.  
  11. for($x = 1; $x <= 2; $x++) // create lines on image
  12. imageline(
  13. $cap,
  14. $x+13,
  15. $x+32,
  16. ($x+8*18),
  17. $x+32,
  18. $lines
  19. );
  20.  
  21. for($x = 1; $x <= $num_letters; $x++) // create letters on image
  22. {
  23. $font = $fonts[array_rand($fonts)];
  24. $generate_letter = substr($gen_reg_key, ($x-6), 1); // $gen_reg_key, ($x-(2*$x)), 1) // $gen_reg_key, ($x-6), 1)
  25.  
  26. $break_letters = ($x+2)*(13+$x);
  27.  
  28. imagettftext(
  29. $cap,
  30. rand(27, 32),
  31. -20+($x*10),
  32. $break_letters,
  33. 45,
  34. $color,
  35. $font,
  36. $generate_letter
  37. );
  38. }
  39.  
  40. imagepng($cap);
  41. ?>


Nowy kod, wyświetlający tylko tło (dalsza częśc jest ignorowana bo imagecolorallocate() nie umie obsłużyć zmiennej $cap:

  1. $gen_reg_key = $key;
  2. header('Content-Type: image/png');
  3.  
  4. $background = ImageCreate(195,63);
  5. $bg = ImageColorAllocate($background,239,239,255);
  6. $fonts = glob('images/anti_robotic_reg/kapczh/*.TTF');
  7. $num_letters = 5;
  8. $cap = imagePng($background);
  9. $lines = imagecolorallocate($cap, 0, 0, 0);
  10. $color = imagecolorallocate($cap, 0, 0, 0);
  11.  
  12. for($x = 1; $x <= 2; $x++) // create lines on image
  13. imageline(
  14. $cap,
  15. $x+13,
  16. $x+32,
  17. ($x+8*18),
  18. $x+32,
  19. $lines
  20. );
  21.  
  22. for($x = 1; $x <= $num_letters; $x++) // create letters on image
  23. {
  24. $font = $fonts[array_rand($fonts)];
  25. $generate_letter = substr($gen_reg_key, ($x-6), 1); // $gen_reg_key, ($x-(2*$x)), 1) // $gen_reg_key, ($x-6), 1)
  26.  
  27. $break_letters = ($x+2)*(13+$x);
  28.  
  29. imagettftext(
  30. $cap,
  31. rand(27, 32),
  32. -20+($x*10),
  33. $break_letters,
  34. 45,
  35. $color,
  36. $font,
  37. $generate_letter
  38. );
  39. }
  40.  
  41. imagepng($cap);
  42. ?>


Ten post edytował Michael2318 27.12.2012, 19:02:38
Go to the top of the page
+Quote Post

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: 24.08.2025 - 08:16