<div align="center">
# GraiaX TextToImage (Playwright)
*基于 Playwright 的适用于 Graia 的文转图工具*
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![License](https://img.shields.io/github/license/GraiaCommunity/graiax-text2img-playwright)](https://github.com/GraiaCommunity/graiax-text2img-playwright/blob/master/LICENSE)
[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)
[![PyPI](https://img.shields.io/pypi/v/graiax-text2img-playwright)](https://img.shields.io/pypi/v/graiax-text2img-playwright)
</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`。
> 我们强烈建议使用包管理器或虚拟环境
## 开始使用
以下示例以 Ariadne 为例。
### 配合 Graia Saya 使用
```python
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)))
```
## 预览
![预览图](preview.jpg)
## 许可证
本项目使用 [`MIT`](./LICENSE) 许可证进行许可。
Raw data
{
"_id": null,
"home_page": "",
"name": "graiax-text2img-playwright",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "graia graiax text2img playwright",
"author": "",
"author_email": "Redlnn <w731347477@gmail.com>, BlueGlassBlock <blueglassblock@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/b4/73/df9a231dea71b71cdc1cc6d5dd0269c378054eed9756ca47f49322b7f038/graiax_text2img_playwright-0.4.3.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n\n# GraiaX TextToImage (Playwright)\n\n*\u57fa\u4e8e Playwright \u7684\u9002\u7528\u4e8e Graia \u7684\u6587\u8f6c\u56fe\u5de5\u5177*\n\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![License](https://img.shields.io/github/license/GraiaCommunity/graiax-text2img-playwright)](https://github.com/GraiaCommunity/graiax-text2img-playwright/blob/master/LICENSE)\n[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)\n[![PyPI](https://img.shields.io/pypi/v/graiax-text2img-playwright)](https://img.shields.io/pypi/v/graiax-text2img-playwright)\n\n</div>\n\nGraiaX TextToImage (Playwright) \u662f\u4e00\u4e2a\u57fa\u4e8e [GraiaX Playwright](https://github.com/GraiaCommunity/graiax-playwright) \u7684\u6587\u8f6c\u56fe\u5de5\u5177\uff0c\n\u5176\u53ef\u4ee5\u5c06\u7eaf\u6587\u672c\u3001Markdown \u6587\u672c\u3001HTML \u4ee3\u7801\u901a\u8fc7 Playwright \u8f6c\u6362\u4e3a\u56fe\u7247\u3002\n\n## \u5b89\u88c5\n\n`pdm add graiax-text2img-playwright` \u6216 `poetry add graiax-text2img-playwright`\u3002\n\n> \u6211\u4eec\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u6216\u865a\u62df\u73af\u5883\n\n## \u5f00\u59cb\u4f7f\u7528\n\n\u4ee5\u4e0b\u793a\u4f8b\u4ee5 Ariadne \u4e3a\u4f8b\u3002\n\n### \u914d\u5408 Graia Saya \u4f7f\u7528\n\n```python\nfrom graiax.shortcut.saya import listen\nfrom graiax.text2img.playwright import HTMLRenderer, convert_md, PageOption, ScreenshotOption\n\nmd = '''\\\n<div align=\"center\">\n\n# GraiaX TextToImage (Playwright)\n\n*\u57fa\u4e8e Playwright \u7684\u9002\u7528\u4e8e Graia \u7684\u6587\u8f6c\u56fe\u5de5\u5177*\n\n</div>\n\nGraiaX TextToImage (Playwright) \u662f\u4e00\u4e2a\u57fa\u4e8e [GraiaX Playwright](https://github.com/GraiaCommunity/graiax-playwright) \u7684\u6587\u8f6c\u56fe\u5de5\u5177\uff0c\n\u5176\u53ef\u4ee5\u5c06\u7eaf\u6587\u672c\u3001Markdown \u6587\u672c\u3001HTML \u4ee3\u7801\u901a\u8fc7 Playwright \u8f6c\u6362\u4e3a\u56fe\u7247\u3002\n\n## \u5b89\u88c5\n\n`pdm add graiax-text2img-playwright` \u6216 `poetry add graiax-text2img-playwright`\u3002\n\n> \u6211\u4eec\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u6216\u865a\u62df\u73af\u5883\n'''\n\n@listen(FriendMessage)\nasync def function(app: Ariadne, friend: Friend):\n image_bytes = await HTMLRenderer().render(\n convert_md(md),\n extra_page_option=PageOption(viewport={\"width\": 840, \"height\": 10}, device_scale_factor=1.5),\n extra_screenshot_option=ScreenshotOption(type=\"jpeg\", quality=80, scale=\"device\"),\n )\n await app.send_message(friend, MessageChain(Image(data_bytes=image_bytes)))\n```\n\n## \u9884\u89c8\n\n![\u9884\u89c8\u56fe](preview.jpg)\n\n## \u8bb8\u53ef\u8bc1\n\n\u672c\u9879\u76ee\u4f7f\u7528 [`MIT`](./LICENSE) \u8bb8\u53ef\u8bc1\u8fdb\u884c\u8bb8\u53ef\u3002\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\u57fa\u4e8e Playwright \u7684\u9002\u7528\u4e8e Graia \u7684\u6587\u8f6c\u56fe\u5de5\u5177",
"version": "0.4.3",
"project_urls": {
"Repository": "https://github.com/GraiaCommunity/graiax-text2img-playwright"
},
"split_keywords": [
"graia",
"graiax",
"text2img",
"playwright"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f04ac89819b08d3f0ecbb5c2e1ce7c663ec3819b8ac626c84166d407d9b33358",
"md5": "a1b39f079520ffe16d18ce49f2c968c7",
"sha256": "194982cb47713728ac644f8c9cda0b1525c9c5f620314e54a3fb789ecce2a76e"
},
"downloads": -1,
"filename": "graiax_text2img_playwright-0.4.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a1b39f079520ffe16d18ce49f2c968c7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 22980,
"upload_time": "2023-12-17T10:02:42",
"upload_time_iso_8601": "2023-12-17T10:02:42.947378Z",
"url": "https://files.pythonhosted.org/packages/f0/4a/c89819b08d3f0ecbb5c2e1ce7c663ec3819b8ac626c84166d407d9b33358/graiax_text2img_playwright-0.4.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b473df9a231dea71b71cdc1cc6d5dd0269c378054eed9756ca47f49322b7f038",
"md5": "6b52e32616a24bf360859df92c5396d3",
"sha256": "8f40ed136527e402942ae0ce36500e9d37bbc88d7bde4bea4c66aef25b32d2ea"
},
"downloads": -1,
"filename": "graiax_text2img_playwright-0.4.3.tar.gz",
"has_sig": false,
"md5_digest": "6b52e32616a24bf360859df92c5396d3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 18883,
"upload_time": "2023-12-17T10:02:44",
"upload_time_iso_8601": "2023-12-17T10:02:44.714863Z",
"url": "https://files.pythonhosted.org/packages/b4/73/df9a231dea71b71cdc1cc6d5dd0269c378054eed9756ca47f49322b7f038/graiax_text2img_playwright-0.4.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-17 10:02:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GraiaCommunity",
"github_project": "graiax-text2img-playwright",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "graiax-text2img-playwright"
}