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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top