Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Zamiana tekstu na grafikę - nowa linia - br [php]
Forum PHP.pl > Forum > PHP
alex011251
Przerabiam pewien kod . Jestem laikiem. Kod ten tworzy z tekstu grafikę . Aczkolwiek chciałbym by tekst był zawijany bądź uznawał br a także nie wiem jak zamienić pole tekstowe na pole typu "<textarea name=... . Chodzi mi o te pole rozszerzone i by te pole jak wyżej uznało entery.
Mam nadzieję iż temat wylądował w dobrym dziale i jakoś pomożecie.

  1. <?php
  2.  
  3. // link to the font file no the server
  4. $fontname = 'font/Verdana.ttf';
  5. // controls the spacing between text
  6. $i=30;
  7. //JPG image quality 0-100
  8. $quality = 90;
  9.  
  10. function create_image($user){
  11.  
  12. global $fontname;
  13. global $quality;
  14. $file = "covers/".md5($user[0]['name'].$user[1]['name'].$user[2]['name']).".jpg";
  15.  
  16. // if the file already exists dont create it again just serve up the original
  17. //if (!file_exists($file)) {
  18.  
  19.  
  20. // define the base image that we lay our text on
  21. $im = imagecreatefromjpeg("pass.jpg");
  22.  
  23. // setup the text colours
  24. $color['grey'] = imagecolorallocate($im, 54, 56, 60);
  25. $color['green'] = imagecolorallocate($im, 55, 189, 102);
  26.  
  27. // this defines the starting height for the text block
  28. $y = imagesy($im) - $height - 500;
  29.  
  30. // loop through the array and write the text
  31. foreach ($user as $value){
  32. // center the text in our image - returns the x value
  33. $x = center_text($value['name'], $value['font-size']);
  34. imagettftext($im, $value['font-size'], 0, $x, $y+$i, $color[$value['color']], $fontname,$value['name']);
  35. // add 32px to the line height for the next text block
  36. $i = $i+25;
  37.  
  38. }
  39. // create the image
  40. imagejpeg($im, $file, $quality);
  41.  
  42. //}
  43.  
  44. return $file;
  45. }
  46.  
  47. function center_text($string, $font_size){
  48.  
  49. global $fontname;
  50.  
  51. $image_width = 800;
  52. $dimensions = imagettfbbox($font_size, 0, $fontname, $string);
  53.  
  54. return ceil(($image_width - $dimensions[1]) / 10);
  55. }
  56.  
  57.  
  58.  
  59. $user = array(
  60.  
  61. 'name'=> 'Tutuł aukcji',
  62. 'font-size'=>'27',
  63. 'color'=>'grey'),
  64.  
  65. 'name'=> 'Treść aukcji - wiersz 1',
  66. 'font-size'=>'11',
  67. 'color'=>'grey'),
  68.  
  69. 'name'=> 'Treść aukcji - wiersz 2',
  70. 'font-size'=>'11',
  71. 'color'=>'grey'
  72. )
  73.  
  74. );
  75.  
  76.  
  77. if(isset($_POST['submit'])){
  78.  
  79. $error = array();
  80.  
  81. if(strlen($_POST['name'])==0){
  82. $error[] = 'Uzupełnij Tytuł';
  83. }
  84.  
  85. if(strlen($_POST['job'])==0){
  86. $error[] = 'Uzupełnij wiersz';
  87. }
  88.  
  89. if(strlen($_POST['email'])==0){
  90. $error[] = 'Uzupełnij wiersz';
  91. }
  92.  
  93. if(count($error)==0){
  94.  
  95. $user = array(
  96.  
  97. 'name'=> $_POST['name'],
  98. 'font-size'=>'27',
  99. 'color'=>'grey'),
  100.  
  101. 'name'=> $_POST['job'],
  102. 'font-size'=>'16',
  103. 'color'=>'grey'),
  104.  
  105. 'name'=> $_POST['email'],
  106. 'font-size'=>'13',
  107. 'color'=>'green'
  108. )
  109.  
  110. );
  111.  
  112. }
  113.  
  114. }
  115.  
  116. // run the script to create the image
  117. $filename = create_image($user);
  118.  
  119. ?>
  120.  
  121. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  122. <html xmlns="http://www.w3.org/1999/xhtml">
  123. <head>
  124. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  125. <title></title>
  126. <link href="../style.css" rel="stylesheet" type="text/css" />
  127.  
  128. <style>
  129. input{
  130. border:1px solid #ccc;
  131. padding:8px;
  132. font-size:14px;
  133. width:300px;
  134. }
  135.  
  136. .submit{
  137. width:110px;
  138. background-color:#FF6;
  139. padding:3px;
  140. border:1px solid #FC0;
  141. margin-top:20px;}
  142.  
  143. </style>
  144.  
  145. </head>
  146.  
  147. <body>
  148.  
  149. <?php include '../includes/header.php';
  150. $link = '| <a href="http://papermashup.com/dynamically-add-form-inputs-and-submit-using-jquery/">Back To Tutorial</a>';
  151. ?>
  152.  
  153. <img src="<?=$filename;?>?id=<?=rand(0,1292938);?>" width="800" height="600"/><br/><br/>
  154.  
  155. <ul>
  156. <?php if(isset($error)){
  157.  
  158. foreach($error as $errors){
  159.  
  160. echo '<li>'.$errors.'</li>';
  161.  
  162. }
  163.  
  164.  
  165. }?>
  166. </ul>
  167.  
  168. <p>Edytor aukcji</p>
  169.  
  170. <div class="dynamic-form">
  171. <form action="" method="post">
  172. <label>Tytuł aukcji</label>
  173. <input type="text" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}?>" name="name" maxlength="15" placeholder="Tytuł aukcji"><br/>
  174. <label>Wiersz 1</label>
  175. <input type="text" value="<?php if(isset($_POST['job'])){echo $_POST['job'];}?>" name="job" placeholder="Wiersz 1"><br/>
  176. <label>Wiersz 2</label>
  177. <input type="text" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" name="email" placeholder="Wiersz 2"><br/>
  178. <input name="submit" type="submit" class="btn btn-primary" value="Wygeneruj aukcje" />
  179.  
  180. </form>
  181. </div>
  182.  
  183.  
  184.  
  185. <?php include '../includes/footer.php';?>
  186.  
  187. </body>
  188. </html>


Pomoże ktoś? Bardzo mi to potrzebne.
LowiczakPL
musisz zrobić EXPLODE dla BR i masz już Twoje linie tekstu

możesz też podzielić tekst na litery lub wyrazy,

dzięki temu znasz określoną ilość linii tekstu czyli Twoje textarea nl2br

i jako BR dajesz kolejną linie tekstu z tablicy, zwiększając Y+ wysokość linii tekstu
alex011251
A da się to jakoś prościel zrobić? bo ja nie mam zielonego pojęcia:
ylko co chwile kwiatki wychodzą ;/
A dokładnie dwa błędy
Jak wpiszę za dużo wierszy to tekst znika na lewo grafiki (nie wiem gdzie mam błąd) . A do tego właśnie te zawijanie. Próbowałem zastosować wrap ale nic z tego.

takie coś
http://fenixweb.pl/edytor-aukcji/index.php
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.