Make a (text to image) image a certain width but unlimited length?

让人想犯罪 __ 提交于 2019-12-02 17:07:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!