Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Tekst w obrazku - imagettftext
KRQ
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 19.01.2009

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


Witam. Chciałbym utworzyć skrypt dzięki któremu wpisywał bym tekst w obrazek. Kod z php.net:

  1. <?php
  2.    
  3. // Set the content-type
  4. header('Content-type: image/png');
  5.  
  6. // Create the image
  7. $im = imagecreatetruecolor(400, 30);
  8.  
  9. // Create some colors
  10. $white = imagecolorallocate($im, 255, 255, 255);
  11. $grey = imagecolorallocate($im, 128, 128, 128);
  12. $black = imagecolorallocate($im, 0, 0, 0);
  13. imagefilledrectangle($im, 0, 0, 399, 29, $white);
  14.  
  15. // The text to draw
  16. $text = 'Tekst';
  17. // Replace path by your own font path
  18. $font = 'arial.ttf';
  19.  
  20. // Add some shadow to the text
  21. imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
  22.  
  23. // Add the text
  24. imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
  25.  
  26. // Using imagepng() results in clearer text compared with imagejpeg()
  27. imagepng($im);
  28. imagedestroy($im);
  29. ?>


Nie wiem co zrobić abym mógł odnosić się do "$text" z zewnętrznego inputboxa. Chodzi o to że wpisuję coś w inputboxie zatwierdzam i mam ten tekst na jako obrazek, na obrazku. Dobrze by było jeśli utworzony obrazek zapisywał w określonym katalogu na serwerze.
Podsunie ktoś jakiś pomysł?

Pozdrawiam.
Powód edycji: bbcode
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
EarthCitizen
post
Post #2





Grupa: Zarejestrowani
Postów: 286
Pomógł: 70
Dołączył: 13.01.2009

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


Na początku przyda Ci się formularz:

formularz.html
  1. <form action="skrypt.php" method="post">
  2. <input type="text" name="text" value="" />
  3. <input type="submit" value="Wyślij" />
  4. </form>


i później w Twoim skrypcie zmieniasz aby wartość zmiennej $text była z $_POST['text']

skrypt.php

  1. <?php
  2. // Set the content-type
  3. header('Content-type: image/png');
  4.  
  5. // Create the image
  6. $im = imagecreatetruecolor(400, 30);
  7.  
  8. // Create some colors
  9. $white = imagecolorallocate($im, 255, 255, 255);
  10. $grey = imagecolorallocate($im, 128, 128, 128);
  11. $black = imagecolorallocate($im, 0, 0, 0);
  12. imagefilledrectangle($im, 0, 0, 399, 29, $white);
  13.  
  14. // The text to draw
  15. $text = $_POST['text'];
  16. // Replace path by your own font path
  17. $font = 'arial.ttf';
  18.  
  19. // Add some shadow to the text
  20. imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
  21.  
  22. // Add the text
  23. imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
  24.  
  25. // Using imagepng() results in clearer text compared with imagejpeg()
  26. imagepng($im);
  27. imagedestroy($im);
  28. ?>


Pomijam walidację formularza itd, bo to nie temat postu...

A co do zapisu obrazka na dysku to drugi argument funkcji imagepng($im, 'nazwa_pliku.png'); więcej na temat funkcji znajdziesz w manualu -> http://php.net.pl/manual/pl/function.imagepng.php

Ten post edytował EarthCitizen 19.01.2009, 18:07:08
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: 15.10.2025 - 15:56