在Python中将HTML字符串转换为图像 [英] Convert HTML string to an image in Python
问题描述
我想将以下HTML转换为Python中的PNG图像.
I want to convert following HTML to PNG image in Python.
<html>
<b>Bold text</b>
</html>
当然,此HTML是一个示例.
This HTML is, of course, an example.
我尝试过比萨",但是它将html转换为PDF,而不转换为图像. 我可以将HTML转换为PDF,然后将PDF转换为PNG,但是我想知道是否有任何直接的解决方案(即HTML转换为PNG).任何内置或外部模块都可以正常工作.
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.
如果可以在Graphicsmagick或Imagemagick中完成,那将是完美的.
If this can be done in Graphicsmagick or Imagemagick, then it will be perfect.
推荐答案
webkit2png..原始版本仅适用于OSX,但幸运的是存在跨平台分支: https://github.com/AdamN/python-webkit2png
webkit2png. The original version is OSX-only, but luckily there is a cross-platform fork: https://github.com/AdamN/python-webkit2png
这篇关于在Python中将HTML字符串转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!