1
我创建了一个图像500X200,上面有白色背景和文字。 如何在GD中包含“Text”。PHP - GD - 如何包装文本
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill ($image, 0, 0, $white);
...
imagettftext($image, 18, 0, $x, 100, $black, $font, "text");
你也许可以使用'imagettfbbox()'函数来确定文本有多大会并将结果与图像的宽度进行比较。 'imagettfbbox()'返回一个点数组,因此您需要根据边界框的左侧和右侧进行一些计算。字符串'$ text'然后可以拆分并插入换行符 – RamRaider