How does PHP generate images with intact webpage content? & Lt ;? Php $ str & nbsp; & lt; meta & nbsp; http-equivContent-Type & nbsp; contenttexthtml; & nbsp; charsetgbk & gt; & lt; div & gt; & lt; font & nbsp; colorred & gt; text & PHP?
$ Str ='
Text Information
Line Feed
';
$ Font_file = "正 gb_ GBK. ttf"; // set the path of some linux
$ Text = $ str; // string to be displayed
$ Font_size = 14; // font size
$ Arr = imagettfbbox ($ font_size, 0, $ font_file, $ text); // determine the position of the variable string
$ Text_width = ($ arr [2]-$ arr [0]) + 10; // String text box length
$ Text_height = ($ arr [3]-$ arr [5]) + 50; // String text box height
$ Im = imagecreate ($ text_width, $ text_height );
$ White = imagecolorallocate ($ im, 255,255,255 );
Imagecolortransparent ($ im, $ white); // imagecolortransparent () sets a specific color to transparent.
$ Blue = imagecolorallocate ($ im, 0, 0 );
$ Arr = imagettftext ($ im, $ font_size, $ text_height-50, $ blue, $ font_file, $ text );
Imageline ($ im, $ arr [0], $ arr [1], $ arr [2], $ arr [3], $ blue );
// Imagettftext ($ im, $ black, "c: \ windows \ Fonts \ simhei. ttf", $ url); // Set the windows path in the font.
Header ("Content-type: image/png ");
Imagepng ($ im );
Imagedestroy ($ im );
?>
Failed to follow the idea in a post of the xuzuning moderator.
Why?
Similar function: converts the content in a specified DIV to an image format. It seems that JS cannot be used, because the server is not a win system, so I want to use a function to directly output the content into an image. I don't know how to block the html format to the output.
Please help the xuzuning moderator! Thank you very much !!
------ Solution ----------------------
You can convert html to pdf and export it as an image, but this is troublesome.
It is easy to use imagemagick to create text images.