How does PHP keep the webpage content intact to generate images?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.