Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Pisanie po obrazku
Forum PHP.pl > Forum > Przedszkole
schin1
Hej! Jestem nowy u was na forum smile.gif
Potrzebuję pomocy,bo nie bardzo wiem jak rozwiązać problem.

Pobrałem skrypt:
http://papermashup.com/php-gd-generate-an-...font-embedding/

Fajnie działa,ale chcę trochę bardziej manipulować tekstem. A konkretnie chcę określić miejsce w którym się pojawi na obrazu.

Czy mógłby ktoś pomoc zielonemu? oneeyedsmiley02.png

  1. // link to the font file no the server
  2. $fontname = 'font/Capriola-Regular.ttf';
  3. // controls the spacing between text
  4. $i=30;
  5. //JPG image quality 0-100
  6. $quality = 85;
  7.  
  8. function create_image($user){
  9.  
  10. global $fontname;
  11. global $quality;
  12. $file = "covers/".md5($user[0]['name'].$user[1]['name'].$user[2]['name']).".jpg";
  13.  
  14. // if the file already exists dont create it again just serve up the original
  15. if (!file_exists($file)) {
  16.  
  17. // define the base image that we lay our text on
  18. $im = imagecreatefromjpeg("pass.jpg");
  19.  
  20. // setup the text colours
  21. $color['grey'] = imagecolorallocate($im, 54, 56, 60);
  22. $color['green'] = imagecolorallocate($im, 55, 189, 102);
  23.  
  24. // this defines the starting height for the text block
  25. $y = imagesy($im) - $height - 365;
  26.  
  27. // loop through the array and write the text
  28. foreach ($user as $value){
  29. // center the text in our image - returns the x value
  30. $x = center_text($value['name'], $value['font-size']);
  31. imagettftext($im, $value['font-size'], 0, $x, $y+$i, $color[$value['color']], $fontname,$value['name']);
  32. // add 32px to the line height for the next text block
  33. $i = $i+32;
  34.  
  35. }
  36. // create the image
  37. imagejpeg($im, $file, $quality);
  38.  
  39. }
  40.  
  41. return $file;
  42. }
  43.  
  44. function center_text($string, $font_size){
  45. global $fontname;
  46. $image_width = 800;
  47. $dimensions = imagettfbbox($font_size, 0, $fontname, $string);
  48. return ceil(($image_width - $dimensions[4]) / 2);
  49. }
  50.  
  51. $user = array(
  52.  
  53. 'name'=> 'Ashley Ford',
  54. 'font-size'=>'27',
  55. 'color'=>'grey'),
  56.  
  57. 'name'=> 'Technical Director',
  58. 'font-size'=>'16',
  59. 'color'=>'grey'),
  60.  
  61. 'name'=> 'ashley[at]papermashup.com',
  62. 'font-size'=>'13',
  63. 'color'=>'green'
  64. )
  65. );
  66.  
  67. // run the script to create the image
  68. $filename = create_image($user);

gitbejbe
przecież masz komentarze w kodzie

3 pierwsze rzeczy do testowania:


// this defines the starting height for the text block
$y = imagesy($im) - $height - 365;

// add 32px to the line height for the next text block
$i = $i+32;

function center_text($string, $font_size){
global $fontname;
$image_width = 800;
$dimensions = imagettfbbox($font_size, 0, $fontname, $string);
return ceil(($image_width - $dimensions[4]) / 2);
}

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-2024 Invision Power Services, Inc.