基于 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.4.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50c6f044992238b91aa80d7d588f1e35ec10be675c23655f678b4448a74bca9d |
|
MD5 | 941ff47f7fa2d19f814cd50022281b22 |
|
BLAKE2b-256 | 240ddaea83e9f024814e278efbe9fdc6c225c9ca78087d399867f348d5552160 |
Close
Hashes for graiax_text2img_playwright-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d201f7ab7ab22d8a7e4daefa3fed0f36b141fd3192e43e94b654d27c29afe5e |
|
MD5 | bf9dc72153facc082406afc2a06bb77e |
|
BLAKE2b-256 | 93c773a83589b6d7360eb775daa02df82a254fa67a0066453a1a6d4f29f2af21 |