基于 Playwright 的适用于 Graia 的文转图工具
Project description
GraiaX TextToImage (Playwright) 是一个基于 GraiaX Playwright 的文转图工具, 其可以将纯文本、Markdown 文本、HTML 代码通过 Playwright 转换为图片。
安装
pdm add graiax-text2img-playwright
或 poetry add graiax-text2img-playwright
。
我们强烈建议使用包管理器或虚拟环境
开始使用
以下示例以 Ariadne 为例。
配合 Graia Saya 使用
from graiax.text2img.playwright import HTMLRenderer, convert_md, PageOption, ScreenshotOption
md = '''\
<div align="center">
# GraiaX TextToImage (Playwright)
*基于 Playwright 的适用于 Graia 的文转图工具*
</div>
GraiaX TextToImage (Playwright) 是一个基于 [GraiaX Playwright](https://github.com/GraiaCommunity/graiax-playwright) 的文转图工具,
其可以将纯文本、Markdown 文本、HTML 代码通过 Playwright 转换为图片。
## 安装
`pdm add graiax-text2img-playwright` 或 `poetry add graiax-text2img-playwright`。
> 我们强烈建议使用包管理器或虚拟环境
'''
@listen(FriendMessage)
async def function(app: Ariadne, friend: Friend):
image_bytes = await HTMLRenderer().render(
convert_md(md),
extra_page_option=PageOption(viewport={"width": 840, "height": 10}, device_scale_factor=1.5),
extra_screenshot_option=ScreenshotOption(type="jpeg", quality=80, scale="device"),
)
await app.send_message(friend, MessageChain(Image(data_bytes=image_bytes)))
预览
许可证
本项目使用 MIT
许可证进行许可。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for graiax-text2img-playwright-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7e507e5e02ca9907238af4f37ac16be10119de2872a6cc2189d15f0d76527bf |
|
MD5 | 69fc4c29679bef5dae7e269dafc4ae0f |
|
BLAKE2b-256 | 291d992350e86b09637a68be41db3cfce504733767af1c596001e02e6f853ac1 |
Close
Hashes for graiax_text2img_playwright-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea69bf84ea4dd91ccec0ada8707b04c2910bc5a5aa8cedc170b68e074d324972 |
|
MD5 | 32986983e8515378d2a566486eb00ef1 |
|
BLAKE2b-256 | d699fc832bb212fbd3e6917680495f0e519347ae7af4908faddf3d35945a1b82 |