Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php] Generowanie obrazka zamiast tekstu
Forum PHP.pl > Forum > Przedszkole
podol
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
nospor
Prosze przyjrzec sie tej linijce:
  1. <?php
  2. $width = abs(arr[2] - $arr[0]) + 5;
  3. ?>


Przenosze na przedszkole
podol
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. ?>
nospor
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...
huntercs
poka¿ kod b³êdu? smile.gif
czyba chodzi Ci raczej o imagettftext a nie imagegettftext
podol
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
huntercs
jak widaæ wypluwa b³êdy o czcionkê ttf, polecam manuala:
imagettftext
podol
  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
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.