Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program that convert html to image

Is there a ready-to-use program, that I can run from my web application, to convert an HTML file to an image? Preferably using Webkit, or another mature browser engine?

I tried wkhtmltoimage, but it doesn't render backgrounds correctly (while wkhtmltopd works fine). Is there one that works?

like image 234
Pydev UA Avatar asked Apr 06 '12 10:04

Pydev UA


People also ask

Can I convert HTML to image?

Converting HTML to JPG with the Windows screen capture tool Open your HTML file in your browser or any viewable tool. Take a snapshot of an area with your screen capture tool (Snipping tool on Windows, for example). Click File > Save as. Select the location and select the Save as type as JPG.


2 Answers

Method A

Using phantomjs

$ phantom rasterize.js http://www.google.com google.png

Download and unzip the binary archive. rasterize.js is in the example directory.

Method B

Using chrome (Tested on MacOSX, should work on other platforms)

$ alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
$ chrome --headless --disable-gpu --screenshot=google.png http://www.google.com

Method C

Using webkit2png (macOS only)

like image 116
kev Avatar answered Oct 20 '22 06:10

kev


simply use firefox

firefox --headless --screenshot google.com

or visit here

like image 26
Kasra Avatar answered Oct 20 '22 06:10

Kasra