How to convert CSS3-based HTML to image [closed]
-
15-06-2021 - |
Question
How can I convert a CSS3 or CSS2-based HTML page into a JPEG or PNG (with transparent background) image?
Is there any command-line tool or php-based API that can be installed on my Linux server and provide me with the best result possible?
Solution
Try using http://code.google.com/p/wkhtmltopdf/. Check downloads sections, there is a wkhtmltoimage
package.
It uses WebKit rendering engine, so your certificate should only look good in Safari/Chrome.
P.S.
Python with Qt4.4 required, but luckily most Linux boxes have python (and probably Qt as well, at least mine does)
Example of running ./wkhtmltoimage-i386 --crop-h 450 http://stackoverflow.com/questions/11096068/how-to-convert-css3-based-html-to-image/11096920#11096920 output.png
OTHER TIPS
If your goal is to make a picture of what the page would look like in a browser, you need an HTML rendering engine (one of a browser's main parts) for that.
PHP doesn't have one of those built-in, but you could use an external program like PhantomJS to do the rendering.
I used CutyCapt command line tool under Windows. It is of course cross-platform.