Saving DIV as Image
I have:
echo" <div id=IwantToSaveThisWholeDivAsAnImage)> <div id=OneOfMultipleDivs> <table>multiple tables rendered here </table> </div> </div>"; I tried (one of many):
$html_code = " <html> <head> <title>Image</title> <style> body { font-family:verdana; font-size:11px; color:black } </style> </head> <body> my tables here </body> </html>"; $img = imagecreate("300", "600"); $c = imagecolorallocate($img, 0, 0, 0); $c2 = imagecolorallocate($img, 255, 255, 255); imageline($img,0,0,300,600,$c); imageline($img,300,0,0,600,$c2); $white = imagecolorallocate($img, 255, 255, 255); imagettftext($img, 9, 0, 1, 1, $white, "arial.tff", '$html_code'); header("Content-type: image/jpeg"); imagejpeg($img); I am not allowed to use external libraries. Read that this can be done with GD, but so far I have not been successful. Any ideas and help would be greatly appreciated! UB
To explain my comment a bit: HTML rendering is done by your browser. PHP is server-side, so it does not know how to render HTML, and never will. This means that you will need βsomethingβ that can display HTML and store the result in the image, while PHP can βtalkβ to it. To do this, wkhtmltoimage works (give it a url and you will get a jpg, which you can then crop). I heard well about phantomjs , which might be even better for your purpose, since you can "select" a specific div.
If you are completely disconnected from using any external tools, you have practically no parameters.
You can do if using a tool like wkhtmltoimage
Since it is not written in php, this means that you can install it on your server and run it with php.
You can create tables and write texts in GD, of course, but not from HTML - you will have to create them yourself (effectively draw tables in rows and then fill them)
As already explained by some other users, HTML is displayed on the client side, not on the server, your php does not know how it will look, and therefore your GD will not.