Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] imagettftext - Textbox ?

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Erledigt] imagettftext - Textbox ?

    Moin,

    kann ich mit einer image - Klasse so etwas wie eine Textbox erstellen?
    Das heißt ich sagen der kasten ist 400px breit und 100px hoch und da soll dann der Text umgebrochen werden falls er drüber hinausgeht usw. usw.

    Würde das ansonsten einfach mit wordwrap + explode machen, dass ich dann nach einer bestimmten anzahl von Zeichen eine neue Zeile beginne.

    Würde mich über Hilfe freuen.

    Danke
    Grüße
    "Dummheit redet viel..Klugheit denkt und schweigt.." [Amgervinus]

  • #2
    Meinst du sowas? PHP: imagettfbbox - Manual <- Allgemein die Funktion und den Beitrag auf den ich verlinkt hab beachten!

    Kommentar


    • #3
      Zitat von affe loco Beitrag anzeigen
      Meinst du sowas? PHP: imagettfbbox - Manual <- Allgemein die Funktion und den Beitrag auf den ich verlinkt hab beachten!
      Jep sowas meine ich.
      Leider funktioniert die Funktion bei mir nicht ( kein Zeilenumbruch vorhanden ).

      edit.:
      Habe was gefunden
      PHP-Code:
      <?php
      // Path to our font file
      $font 'arial.ttf';
      $fontsize 10;

      // array of random quotes
      $quotes = array(
      "Did you hear about the guy whose whole left side was cut off? He's all right now.",
      "There was a sign on the lawn at a drug re-hab center that said 'Keep off the Grass'.",
      "Police were called to a daycare where a three-year-old was resisting a rest.",
      "A hole has been found in the nudist camp wall. The police are looking into it.",
      "When a clock is hungry it goes back four seconds.",
      "Time flies like an arrow. Fruit flies like a banana.",
      "Local Area Network in Australia: the LAN down under.",
      "Alcohol and calculus don't mix so don't drink and derive.");

      // generate a random number with range of # of array elements
      $pos rand(0,count($quotes)-1);
      // get the quote and word wrap it
      $quote wordwrap($quotes[$pos],20);

      // create a bounding box for the text
      $dims imagettfbbox($fontsize0$font$quote);

      // make some easy to handle dimension vars from the results of imagettfbbox
      // since positions aren't measures in 1 to whatever, we need to
      // do some math to find out the actual width and height
      $width $dims[4] - $dims[6]; // upper-right x minus upper-left x 
      $height $dims[3] - $dims[5]; // lower-right y minus upper-right y

      // Create image
      $image imagecreatetruecolor($width,$height);

      // pick color for the background
      $bgcolor imagecolorallocate($image100100100);
      // pick color for the text
      $fontcolor imagecolorallocate($image255255255);

      // fill in the background with the background color
      imagefilledrectangle($image00$width$height$bgcolor);

      // x,y coords for imagettftext defines the baseline of the text: the lower-left corner
      // so the x coord can stay as 0 but you have to add the font size to the y to simulate
      // top left boundary so we can write the text within the boundary of the image
      $x 0
      $y $fontsize;
      imagettftext($image$fontsize0$x$y$fontcolor$font$quote);

      // tell the browser that the content is an image
      header('Content-type: image/png');
      // output image to the browser
      imagepng($image);

      // delete the image resource 
      imagedestroy($image);
      ?>
      Quelle: http://www.phpfreaks.com/tutorial/php-add-text-to-image

      Das ist zwar nicht ganz das was ich mir gewünscht hatte ( das wäre meine Notfalllösung gewesen wenn ich es selbst gemacht habe [ siehe Post #1 ] ) aber naja... Man kann nicht alles haben *gg*

      Danke
      cu
      Grüße
      "Dummheit redet viel..Klugheit denkt und schweigt.." [Amgervinus]

      Kommentar

      Lädt...
      X