HTML file as screenshot .jpg or other image

Nothing to do with displaying a single image on a web page. The goal is to make the entire web page saved as a screenshot. Want to show thumbnail of HTML file to user. The HTML file that I will capture from the screen will be part of the HTML in the MIME email - ideally I would like to take a snapshot of the entire MIME file, but if I can do this in the HTML file, I will be in good shape.

An API would be ideal, but the executable is also good.

+4
source share
2 answers

I am going with wkhtmltoimage. This worked correctly with the xvfb setup. The postscript sentence did not display correctly, and we need img not pdf.

0
source

You need html2ps and convert from ImageMagick package:

html2ps index.html index.ps convert index.ps index.png 

The second program creates one png per page for a long html page - the page layout was executed by html2ps.

I found the evince-thumbnailer program reported as:

 apropos postscript | grep -i png evince-thumbnailer (1) - create png thumbnails from PostScript and PDF documents 

but it did not work on a simple, first test.

If you like to combine several pages with a large image, the converter will help you.

Now I see that the converter works directly with html, so

 convert index.html index.png 

will work too. I see no difference in output, and the size of the images is almost identical.

If you have a multi-user type of email, you usually have a mail header, maybe some pre-html text, html and possibly attachments.

You can extract the html and format it separately, but making it inline may not be that simple.

Here is the file that I tested, which was from April 14, so I extract one letter from the mail folder:

 sed -n "/From - Sat Apr 14/,/From -/p" /home/stefan/.mozilla-thunderbird/k2jbztqu.default/Mail/Local\ Folders-1/Archives.sbd/sample | \ sed -n '/<html>/,/<\/html>/p' | wkhtmltopdf - - > sample.pdf 

then I only extract the html part of this.

wkhtmltopdf is required - - to read stdin / writing in stdout. PDF rendering, but I don’t know how to integrate it into the workflow.

You can replace wkhtml ... with

  convert - sample.jpg 
+1
source

Source: https://habr.com/ru/post/1411634/


All Articles