I want to convert following HTML to PNG image in Python.
Bold text
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.
解决方案
webkit2png. The original version is OSX-only, but luckily there is a cross-platform fork:
https://github.com/AdamN/python-webkit2png
在Python中,需求是从HTML直接转换为PNG图像。尝试使用pisa库但发现它仅支持HTML到PDF的转换。虽然可以先将HTML转为PDF再转成PNG,但寻求更直接的方法。解决方案是使用webkit2png,这是一个跨平台的Python库,能够实现从HTML到PNG的转换。推荐使用AdamN的python-webkit2png fork,它在各种操作系统上都能运行。

395

被折叠的 条评论
为什么被折叠?



