php – 如何在多行(段落中)中编写文本?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 如何在多行(段落中)中编写文本?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
当我使用这段代码时,我可以用文字制作图像,但是在一行中,

function wrITetext($image_path,$imgdestpath,$x,$y,$angle,$text,$font,$fontsize) {
      $image=imagecreatefromjPEg("$image_path");
      $height = imageSY($image);
      $width = imageSX($image);
      $color = imagecolorallocate($image,0);
      $textwidth = $width;
      imageTTFtext($image,$fontsize,$color,$text );
      ImageJPEG($image,$imgdestpath);
}

请告诉我如何在多行段落中制作此图像?

@H_403_16@解决方法
对于每一行,您需要使用$y的新值调用新的imageTTFtext函数
例如:

$text = 'Lorem ipsum dolor sit amet,consectetur adipiscing elit. Integer non nunc lectus.     Curabitur hendrerit bibendum enim dignissim tempus. Suspendisse non ipsum auctor metus consectetur eleifend. Fusce cursus ullamcorper SEM nec ultricies. Aliquam erat volutpat. Vivamus massa justo,pharetra et soDales quis,rhoncus in ligula. Integer dolor velit,ultrices in iaculis nec,viverra ut nunc.';

// break it up into pieces 125 characters long
$lines = explode('|',wordwrap($text,115,'|'));

// Starting Y position
$y = 513;

// Loop through the lines and place them on the image
foreach ($lines as $line)
{
imagettftext($image,$font_size,50,$font_color,$line);

// Increment Y so the next line is below the prevIoUs line
$y += 23;
}

source

脚本宝典总结

以上是脚本宝典为你收集整理的php – 如何在多行(段落中)中编写文本?全部内容,希望文章能够帮你解决php – 如何在多行(段落中)中编写文本?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。