问题
Is it possible? \n doesnt work, html doesnt work, nothing seems to work. I know I could just make a new string instead, but that is more effort than should be needed for this simple task.
How can I do this?
回答1:
i think you can't
you have to output a new string some pixels lower than the previous.
\n won't do a linebreak for you...
回答2:
You can't insert line breaks, you can get the bounding box of any truetype font by using the imagettfbbox function.
You might want to take a look at the comments on that page and the comments on the imagettftext function page, they might have the answer you are looking for.
回答3:
At this moment you can't.
However use something like this can be more convenient if you get a lot of lines:
$margin = 10;
$font-size = 25;
$top = 10;//y
$left = 10;//x
imagettftext($img, $font-size, 0, $left, $top, $black, './arial.ttf', 'line1');
imagettftext($img, $font-size, 0, $left, $top +($font-size + $margin']), $black, './arial.ttf', 'line2');
imagettftext($img, $font-size, 0, $left, $top +($font-size + $margin'])*2, $black, './arial.ttf', 'line3');
imagettftext($img, $font-size, 0, $left, $top +($font-size + $margin'])*3, $black, './arial.ttf', '...');
You can easily make a function to write multiple lines with this.
来源:https://stackoverflow.com/questions/1750641/new-lines-in-a-string-with-gd-library