您现在的位置是:首页 > 电脑 > 

如何在多行(段落中)中写入文本?(How to write text in multiline(in a paragraph)?)

2025-07-24 05:56:08
如何在多行(段落中)中写入文本?(How to write text in multiline(in a paragraph)?) 当我使用这段代码时,我可以用文字制作图像,但是在一行中, function writetext($image_path,$imgdestpath,$x,$y,$angle,$text,$font,$fontsize) {
如何在多行(段落中)中写入文本?(How to write text in multiline(in a paragraph)?)

当我使用这段代码时,我可以用文字制作图像,但是在一行中,

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,0,0); $textwidth = $width; imageTTFtext($image,$fontsize,$angle,$x,$y,$color,$font, $text ); ImageJPEG($image,$imgdestpath); }

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

When i use this code,I can make a image out of text,but in a single line,

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,0,0); $textwidth = $width; imageTTFtext($image,$fontsize,$angle,$x,$y,$color,$font, $text ); ImageJPEG($image,$imgdestpath); }

Please tell how to make this image in a multiline paragraph??

最满意答案

对于每一行,您需要使用$ y的新值调用新的imageTTFtext函数,例如:

$text = 'Lorem ipsum dolor sit amet, cectetur adipiscing elit. Integer non nunc lectus. Curabitur hendrerit bibendum enim dignissim tempus. Suspendisse non ipsum auctor metus cectetur 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 = 51; // Loop through the lines and place them on the image foreach ($lines as $line) { imagettftext($image, $font_size, 0, 50, $y, $font_color, $font, $line); // Increment Y so the next line is below the previous line $y += 2; }

资源

For each line you need new imageTTFtext function to be called with new value for $y for example:

$text = 'Lorem ipsum dolor sit amet, cectetur adipiscing elit. Integer non nunc lectus. Curabitur hendrerit bibendum enim dignissim tempus. Suspendisse non ipsum auctor metus cectetur 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 = 51; // Loop through the lines and place them on the image foreach ($lines as $line) { imagettftext($image, $font_size, 0, 50, $y, $font_color, $font, $line); // Increment Y so the next line is below the previous line $y += 2; }

source

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/697392.html

相关标签:无
上传时间: 2023-08-27 09:52:19
留言与评论(共有 14 条评论)
本站网友 国内期货行情
7分钟前 发表
$y
本站网友 4b
21分钟前 发表
$line); // Increment Y so the next line is below the previous line $y += 2; } 资源 For each line you need new imageTTFtext function to be called with new value for $y for example
本站网友 冬瓜子能吃吗
1分钟前 发表
$imgdestpath); } 请告诉我如何在多行段落中制作此图像? When i use this code
本站网友 创业网站
17分钟前 发表
$font
本站网友 当代商城打折信息
8分钟前 发表
I can make a image out of text
本站网友 重庆网站联盟
0秒前 发表
viverra ut nunc.'; // Break it up into pieces 125 characters long $lines = explode('|'
本站网友 完美国际任务
7分钟前 发表
$font_size
本站网友 新能源电池
7分钟前 发表
115
本站网友 玻尿酸瑞兰2号
22分钟前 发表
function writetext($image_path
本站网友 膨体隆鼻缺点
3分钟前 发表
$y
本站网友 早餐吃什么减肥最有效
26分钟前 发表
pharetra et sodales quis
本站网友 肉松怎么吃
30分钟前 发表
$font_color
本站网友 天权奇阵
29分钟前 发表
$y