Convert HTML string to an image in Python

mannan picture mannan · Apr 12, 2011 · Viewed 55k times · Source

I want to convert following HTML to PNG image in Python.

<html>
    <b>Bold text</b>
</html>

This HTML is, of course, an example.

I have tried 'pisa' but it converts html to PDF, not to image. I can convert HTML to PDF and then convert PDF to PNG, but I was wondering if there is any direct solution (i.e HTML to PNG). Any built-in or external module will work nicely.

If this can be done in Graphicsmagick or Imagemagick, then it will be perfect.

Answer

vartec picture vartec · Apr 12, 2011

webkit2png. The original version is OSX-only, but luckily there is a cross-platform fork: https://github.com/AdamN/python-webkit2png