【问题标题】:Can I use trim() with imagettftext() in php?我可以在 php 中使用 trim() 和 imagettftext() 吗?
【发布时间】:2014-12-03 06:21:24
【问题描述】:

我需要在由 php 函数创建的 png 文件中换行:imagettftext(); 它对我有用,但我需要换行:

    $arrText=explode("\n",wordwrap($text,20,"\n"));

    $y=5; //vertical position of text
    foreach($arrText as $arr)
    {
        imagestring($image,10,15,$y,trim($arr),$white);
      $y=$y+15;
    }

但我不能将我的自定义字体与 imagestring() 一起使用。

最好的解决方案是什么?

【问题讨论】:

  • imagettftext 返回一个坐标数组。究竟你期望能够trim() 是什么? trim() 需要一个字符串

标签: php fonts gd


【解决方案1】:

我用:

$arrText=explode("\n",wordwrap($text,50,"\n"));

$y=120; //vertical position of text
foreach($arrText as $arr)
{
    imagettftext($image, 20, 0, 40, $y, $mycolor, $font, trim($arr));
 // imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
  $y=$y-40;

}

而且它是使用完整的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    • 2011-01-16
    • 2014-05-13
    相关资源
    最近更新 更多