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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file graiax_text2img_playwright-0.5.0.tar.gz.

File metadata

File hashes

Hashes for graiax_text2img_playwright-0.5.0.tar.gz
Algorithm Hash digest
SHA256 98cf673b25de664fdb5810c024472f427a90d7c37ff582f4ddfddc763455f259
MD5 ddf898e6c153fa585c0f6703f3a80025
BLAKE2b-256 89bf168e7220e06ea9950adb06ddb1d954108ac52a839cc0eea50a7bb8ec48e6

See more details on using hashes here.

File details

Details for the file graiax_text2img_playwright-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for graiax_text2img_playwright-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6ec8f3e7ee8daf22f46bc3cd97b90ddfd1eb892fb1f6e42a3e581a951929e9b
MD5 0dda9dce5b5ff42d7a74d77f3192243d
BLAKE2b-256 fae8b893dabe7af7948705ca8b228260d4ec14288553ba106bbefa4eaf52485d

See more details on using hashes here.

Supported by

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