基于 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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d7d88cee11e0d5ab92d7770a305781a0b31aa0e11bc5acf906f770b357e7a2c |
|
MD5 | 11e8ae3c30b4356fe8c1b295287d9b78 |
|
BLAKE2b-256 | fa6027ebde758fbfe76acfa16cbc22a7ad3160ee686067391b0d1e35e07b8b6e |
Close
Hashes for graiax_text2img_playwright-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49c776f011697a50a59ce5215dab7968174e0d2e8ae27d5e0be56e69be5b0801 |
|
MD5 | 8ff1a19883939fea678b6e8ec6535675 |
|
BLAKE2b-256 | 1fdc4a72a1ebadf3a7efcfaf69f0f07262bbc039713a1fc2f6605423c9842621 |