Skip to main content

基于 Playwright 的适用于 Graia 的文转图工具

Project description

GraiaX TextToImage (Playwright)

基于 Playwright 的适用于 Graia 的文转图工具

Code style: black Imports: isort License pdm-managed PyPI

GraiaX TextToImage (Playwright) 是一个基于 GraiaX Playwright 的文转图工具, 其可以将纯文本、Markdown 文本、HTML 代码通过 Playwright 转换为图片。

安装

pdm add graiax-text2img-playwrightpoetry add graiax-text2img-playwright

我们强烈建议使用包管理器或虚拟环境

开始使用

以下示例以 Ariadne 为例。

配合 Graia Saya 使用

from graiax.shortcut.saya import listen
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graiax_text2img_playwright-0.5.0.tar.gz (19.1 kB view hashes)

Uploaded Source

Built Distribution

graiax_text2img_playwright-0.5.0-py3-none-any.whl (23.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page