New lines in a string with GD library

岁酱吖の 提交于 2019-12-25 03:27:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!