Php 使(文本到图像)图像具有一定的宽度但不受限制的长度?

Php 使(文本到图像)图像具有一定的宽度但不受限制的长度?,php,gd,Php,Gd,我有下面的代码,使大量的文本图像。我希望图像的宽度为700px。我还希望它保持字符串的段落结构。(字符串来自MySQL数据库。)我如何实现这一点 $font = 2; $width = imagefontwidth($font) * strlen($string); $height = imagefontheight($font);

我有下面的代码,使大量的文本图像。我希望图像的宽度为700px。我还希望它保持字符串的段落结构。(字符串来自MySQL数据库。)我如何实现这一点

                            $font  = 2;
                        $width  = imagefontwidth($font) * strlen($string);
                        $height = imagefontheight($font);

                        $image = imagecreatetruecolor ($width,$height);
                        $white = imagecolorallocate ($image,255,255,255);
                        $black = imagecolorallocate ($image,0,0,0);
                        imagefill($image,0,0,$white);

                        imagestring ($image,$font,0,0,$string,$black);

                ob_start();

                imagepng($image);
                printf('<img src="data:image/png;base64,%s"/>', base64_encode(ob_get_clean()));

                imagedestroy($image);
$font=2;
$width=imagefontwidth($font)*strlen($string);
$height=imagefontheight($font);
$image=imageCreateTureColor($width,$height);
$white=imagecolorallocate($Image255255);
$black=imagecolorallocate($image,0,0,0);
图像填充($image,0,0,$white);
imagestring($image,$font,0,0,$string,$black);
ob_start();
imagepng($image);
printf(“”,base64_编码(ob_get_clean());
图像销毁($图像);

第二,撇号不显示的原因是什么?我在图像的开头和结尾看到了一些奇怪的字符?

你能添加字符串的示例吗??或者把它放在一个例子的可能副本中:它只是一篇普通的文章。