gpt4 book ai didi

php - 如何在多行(段落)中书写文本?

转载 作者:可可西里 更新时间:2023-10-31 22:13:06 27 4
gpt4 key购买 nike

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

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);
}

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

最佳答案

对于每一行,您都需要用新的 $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, 0, 50, $y, $font_color, $font, $line);

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

source

关于php - 如何在多行(段落)中书写文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14090340/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com