I have the code below that makes an image out of a large amount of text. I want that image to be 700px wide. I also want it to keep the paragraph structure that the string has. (the string is from a MySQL database.) How can i achieve that?
$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);
Secondly, is there a reason why apostrophes aren't showing and I get some weird characters at the start and end of the image?
来源:https://stackoverflow.com/questions/12872193/make-a-text-to-image-image-a-certain-width-but-unlimited-length