Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Generowanie obrazka zamiast tekstu
podol
post 27.03.2006, 17:57:07
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 12.07.2005
Skąd: Starogard Gdański

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


mam taki skrypt:

  1. <?
  2.  
  3. function getImageWithText($text, $font, $size)
  4. {
  5. $arr = imagettfbbox($size, o, $font, $text);
  6. $width = abs(arr[2] - $arr[0]) + 5;
  7. $height = abs($arr[1] - $arr[7]) + 1;
  8. $img = imagecreatetruecolor($width, $height);
  9. $white = imagecolorallocate($img, 255, 255, 255);
  10. $black = imagecolorallocate($img, 0, 0, 0);
  11.  
  12. imagefill($img, o, o, $white);
  13. imagegettftext($img, $size, 0, 0, $height - 5, $black, $font, $text);
  14.  
  15. return $img;
  16.  
  17. }
  18.  
  19. $img = getImageWithText("napis", "arial.ttf", 30);
  20. imagejpeg($img);
  21. imagedestroy($img);
  22.  
  23. ?>


Niestety pojawia się błąd:

Kod
Parse error: syntax error, unexpected '[' in C:\Program Files\WebServ\httpd\skrypt.php on line 6


Może ktoś mi pomoże

Ten post edytował podol 27.03.2006, 18:07:01
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
nospor
post 27.03.2006, 17:58:21
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Prosze przyjrzec sie tej linijce:
  1. <?php
  2. $width = abs(arr[2] - $arr[0]) + 5;
  3. ?>


Przenosze na przedszkole


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
podol
post 27.03.2006, 18:00:44
Post #3





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 12.07.2005
Skąd: Starogard Gdański

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


O kurde faktycznie ... zapomnialem o
Kod
$


tyle że wyskakuje błąd w linijce 13:

  1. <?php
  2.  imagegettftext($img, $size, 0, 0, $height - 5, $black, $font, $text);
  3. ?>


Ten post edytował podol 27.03.2006, 18:04:30
Go to the top of the page
+Quote Post
nospor
post 27.03.2006, 18:09:21
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




jesli juz, to chyba raczej tu:
  1. <?php
  2. imagefill($img, o, o, $white);
  3. ?>

nie uwazasz, ze powino byc:
  1. <?php
  2. imagefill($img, 0, 0, $white);
  3. ?>
?

pozatym jak ci wyskakuje blad, to podaj jaki...


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
huntercs
post 27.03.2006, 18:16:12
Post #5





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 6.02.2005

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


pokaż kod błędu? smile.gif
czyba chodzi Ci raczej o imagettftext a nie imagegettftext


--------------------


Go to the top of the page
+Quote Post
podol
post 27.03.2006, 18:27:44
Post #6





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 12.07.2005
Skąd: Starogard Gdański

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


Teraz wyglada to tak:

  1. <?
  2.  
  3. function getImageWithText($text, $font, $size)
  4. {
  5. $arr = imagettfbbox($size, 0, $font, $text);
  6. $width = abs($arr[2] - $arr[0]) + 5;
  7. $height = abs($arr[1] - $arr[7]) + 1;
  8. $img = imagecreatetruecolor($width, $height);
  9. $white = imagecolorallocate($img, 255, 255, 255);
  10. $black = imagecolorallocate($img, 0, 0, 0);
  11.  
  12. imagefill($img, o, o, $white);
  13. imagettftext($img, $size, 0, 0, $height - 5, $black, $font, $text);
  14.  
  15. return $img;
  16.  
  17. }
  18.  
  19. $img = getImageWithText("napis", "arial.ttf", 30);
  20. imagejpeg($img);
  21. imagedestroy($img);
  22.  
  23. ?>


A wyskakuja bledy:

Kod
Warning: imagettfbbox(): Could not find/open font in /skrypt.php on line 5

Warning: imagettftext(): Could not find/open font in /skrypt.php on line 13


Ten post edytował podol 27.03.2006, 18:28:16
Go to the top of the page
+Quote Post
huntercs
post 27.03.2006, 18:37:52
Post #7





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 6.02.2005

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


jak widać wypluwa błędy o czcionkę ttf, polecam manuala:
imagettftext


--------------------


Go to the top of the page
+Quote Post
podol
post 27.03.2006, 18:45:04
Post #8





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 12.07.2005
Skąd: Starogard Gdański

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


  1. <?php
  2. // Set the content-type
  3. header("Content-type: image/png");
  4.  
  5. // Create the image
  6. $im = imagecreate(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.  
  13. // The text to draw
  14. $text = 'Testing...';
  15. // Replace path by your own font path
  16. $font = 'arial.ttf';
  17.  
  18. // Add some shadow to the text
  19. imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
  20.  
  21. // Add the text
  22. imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
  23.  
  24. // Using imagepng() results in clearer text compared with imagejpeg()
  25. imagepng($im);
  26. imagedestroy($im);
  27. ?>


Uzylem tego wszystko dziala jak nalezy. Dzieki! biggrin.gif

Ten post edytował podol 27.03.2006, 18:45:44
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: 19.07.2025 - 09:49