0

If i write a text on a picture with code below, code tries to type all the text in one line. So text overflows out of the image like in picture1. I want to write it like in picture2.

If there is a function in php which enables writting like in picture2 what is it?
If there is no function to do that, how can i do it by writting my code? Can you give me a clue?

$text = $_POST['text']; // Text comes from a form.

$im = @imagecreate(700, 350)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagettftext($im, 22, 0, 5, 25,  $text_color, 'fonts/COOLVETICA RG.TTF', properText($text));
imagepng($im, 'image.png');

Picture1:

Picture one


Picture2:

enter image description here

mcan
  • 1,914
  • 3
  • 32
  • 53
  • 2
    you will have to take a measurement based on the font-size and image width and set the chars per line dynamically – DevZer0 Sep 03 '13 at 15:03
  • @DevZer0 Then this function splits the words. How can i prevent it? – mcan Sep 03 '13 at 15:06
  • GD is a VERY simplistic library. If you want linebreaks, you'll have to do put them in yourself, by calling the text function repeatedly with different string chunks and draw coordinates – Marc B Sep 03 '13 at 15:07

1 Answers1

1

Put it in a bounding box using imagettfbbox() then the text will wrap. There's a full example on php.net:

http://www.php.net/manual/en/function.imagettfbbox.php

Moob
  • 14,420
  • 1
  • 34
  • 47