python 字符串转图片,在Python中将HTML字符串转换为图像

在Python中,需求是从HTML直接转换为PNG图像。尝试使用pisa库但发现它仅支持HTML到PDF的转换。虽然可以先将HTML转为PDF再转成PNG,但寻求更直接的方法。解决方案是使用webkit2png,这是一个跨平台的Python库,能够实现从HTML到PNG的转换。推荐使用AdamN的python-webkit2png fork,它在各种操作系统上都能运行。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值