我有几行代码可以在 php 中生成带有一些给定文本的普通图像。但是当我为图像文本指定宽度时,它会超出图像。如何将图像内的文本与固定宽度但动态高度对齐?我的代码如下。
header ("Content-type: image/png");
$string = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s';
$font = 4;
$width = ImageFontWidth($font) * strlen($string);
$height = ImageFontHeight($font);
$im = @imagecreate (200,500);
$background_color = imagecolorallocate ($im, 255, 255, 255); //white background
$text_color = imagecolorallocate ($im, 0, 0,0);//black text
imagestring ($im, $font, 0, 0, $string, $text_color);
imagepng ($im);
我希望这张图片能够根据给定的段落自动调整文本。怎么做?