nonebot-plugin-cardimg 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_cardimg-0.1.0/LICENSE +21 -0
- nonebot_plugin_cardimg-0.1.0/PKG-INFO +345 -0
- nonebot_plugin_cardimg-0.1.0/README.md +329 -0
- nonebot_plugin_cardimg-0.1.0/docs/bili-demo.png +0 -0
- nonebot_plugin_cardimg-0.1.0/docs/help-demo.png +0 -0
- nonebot_plugin_cardimg-0.1.0/docs/minote-demo.png +0 -0
- nonebot_plugin_cardimg-0.1.0/docs/ncm-card-demo.png +0 -0
- nonebot_plugin_cardimg-0.1.0/docs/ncm-zhusha-demo.png +0 -0
- nonebot_plugin_cardimg-0.1.0/docs/qrcode.png +0 -0
- nonebot_plugin_cardimg-0.1.0/docs/simple-demo.png +0 -0
- nonebot_plugin_cardimg-0.1.0/docs/table-demo.png +0 -0
- nonebot_plugin_cardimg-0.1.0/pyproject.toml +27 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/__init__.py +133 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/base.py +82 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/config.py +22 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/bili/bili_dark.jpg +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/bili/bili_light.jpg +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/bili/day.html +46 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/bili/night.html +46 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/help/day.html +117 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/help/night.html +120 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/minote/background.png +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/minote/banner_01.png +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/minote/banner_02.png +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/minote/banner_03.png +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/minote/banner_04.png +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/minote/template.html +98 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/ncm_card/background.png +0 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/ncm_card/template.html +88 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/ncm_zhusha/template.html +59 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/simple/template.html +47 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/table/day.html +175 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates/table/night.html +179 -0
- nonebot_plugin_cardimg-0.1.0/src/nonebot_plugin_cardimg/templates.py +339 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 youlanan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nonebot_plugin_cardimg
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 文本转图片工具,基于 nonebot_plugin_htmlkit 预制了方便扩展的渲染模板
|
|
5
|
+
Project-URL: homepage, https://github.com/youlanan/nonebot-plugin-cardimg
|
|
6
|
+
Project-URL: Repository, https://github.com/youlanan/nonebot_plugin_cardimg.git
|
|
7
|
+
Project-URL: Documentation, https://github.com/youlanan/nonebot_plugin_cardimg#readme
|
|
8
|
+
Author-email: youlanan <ylanan@foxmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Python: <4.0,>=3.10
|
|
12
|
+
Requires-Dist: nonebot-plugin-htmlkit>=0.1.0
|
|
13
|
+
Requires-Dist: nonebot2>=2.4.3
|
|
14
|
+
Requires-Dist: pydantic>=2.0.0
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
<!-- markdownlint-disable MD031 MD033 MD036 MD041 -->
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
|
|
21
|
+
<a href="https://v2.nonebot.dev/store">
|
|
22
|
+
<img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
|
|
23
|
+
</a>
|
|
24
|
+
|
|
25
|
+
<p>
|
|
26
|
+
<img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
# nonebot-plugin-cardimg
|
|
30
|
+
|
|
31
|
+
_✨ 基于 nonebot_plugin_htmlkit 渲染的文本转图片模板插件 ✨_
|
|
32
|
+
|
|
33
|
+
<img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="python">
|
|
34
|
+
<a href="https://github.com/astral-sh/uv">
|
|
35
|
+
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
|
|
36
|
+
</a>
|
|
37
|
+
<a href="https://pydantic.dev">
|
|
38
|
+
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/pyd-v1-or-v2.json" alt="Pydantic Version 1 Or 2" >
|
|
39
|
+
</a>
|
|
40
|
+
<a href="./LICENSE">
|
|
41
|
+
<img src="https://img.shields.io/github/license/youlanan/nonebot-plugin-cardimg.svg" alt="license">
|
|
42
|
+
</a>
|
|
43
|
+
<a href="https://pypi.python.org/pypi/nonebot_plugin_cardimg">
|
|
44
|
+
<img src="https://img.shields.io/pypi/v/nonebot_plugin_cardimg.svg" alt="pypi">
|
|
45
|
+
</a>
|
|
46
|
+
|
|
47
|
+
<br />
|
|
48
|
+
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
## 📖 介绍
|
|
52
|
+
|
|
53
|
+
nonebot-plugin-cardimg 是一个基于 nonebot_plugin_htmlkit 的模板化图片渲染插件,为 NoneBot2 插件开发者提供简单易用的文本图片生成功能。
|
|
54
|
+
|
|
55
|
+
### 核心特性
|
|
56
|
+
|
|
57
|
+
- **多种预设模板**:提供 7 种精美模板,覆盖常见使用场景
|
|
58
|
+
- **昼夜模式**:部分模板支持自动/手动切换昼夜主题
|
|
59
|
+
- **随机配色**:部分模板支持随机颜色主题
|
|
60
|
+
- **灵活配置**:支持全局配置和模板特定参数
|
|
61
|
+
- **资源缓存**:内置文件和资源缓存机制,提升性能
|
|
62
|
+
- **易于扩展**:基于抽象基类,方便添加自定义模板
|
|
63
|
+
|
|
64
|
+
### 可用模板
|
|
65
|
+
|
|
66
|
+
| 模板名称 | 描述 | 特性 |
|
|
67
|
+
| :--- | :--- | :--- |
|
|
68
|
+
| `minote` | 小米便签风格 | 背景图+边框+四角装饰 |
|
|
69
|
+
| `simple` | 简约风格 | 纯色背景,支持昼夜模式 |
|
|
70
|
+
| `ncm_zhusha` | 网易云朱砂样式 | 红色背景+白色标题框 |
|
|
71
|
+
| `ncm_card` | 网易云热评卡片 | 音乐评论卡片样式 |
|
|
72
|
+
| `bili` | 哔哩哔哩壁纸 | 支持昼夜模式 |
|
|
73
|
+
| `help` | 帮助文档 | 支持随机颜色主题和昼夜模式 |
|
|
74
|
+
| `table` | 表格展示 | 支持随机颜色主题和昼夜模式 |
|
|
75
|
+
|
|
76
|
+
## 🖼️ 演示效果
|
|
77
|
+
|
|
78
|
+
<details>
|
|
79
|
+
<summary>点击展开查看各模板渲染效果</summary>
|
|
80
|
+
|
|
81
|
+
### 小米便签 (minote)
|
|
82
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/minote-demo.png" width="400">
|
|
83
|
+
|
|
84
|
+
### 简约风格 (simple)
|
|
85
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/simple-demo.png" width="400">
|
|
86
|
+
|
|
87
|
+
### 网易云朱砂 (ncm_zhusha)
|
|
88
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/ncm-zhusha-demo.png" width="400">
|
|
89
|
+
|
|
90
|
+
### 网易云热评卡片 (ncm_card)
|
|
91
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/ncm-card-demo.png" width="400">
|
|
92
|
+
|
|
93
|
+
### 哔哩哔哩壁纸 (bili)
|
|
94
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/bili-demo.png" width="400">
|
|
95
|
+
|
|
96
|
+
### 帮助文档 (help)
|
|
97
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/help-demo.png" width="400">
|
|
98
|
+
|
|
99
|
+
### 表格展示 (table)
|
|
100
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/table-demo.png" width="400">
|
|
101
|
+
|
|
102
|
+
</details>
|
|
103
|
+
|
|
104
|
+
## 安装
|
|
105
|
+
|
|
106
|
+
以下提到的方法 任选**其一** 即可
|
|
107
|
+
|
|
108
|
+
<details open>
|
|
109
|
+
<summary>[推荐] 使用 nb-cli 安装</summary>
|
|
110
|
+
|
|
111
|
+
在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
nb plugin install nonebot_plugin_cardimg
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
</details>
|
|
118
|
+
|
|
119
|
+
<details>
|
|
120
|
+
<summary>使用包管理器安装</summary>
|
|
121
|
+
|
|
122
|
+
在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary>pip</summary>
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pip install nonebot_plugin_cardimg
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
</details>
|
|
132
|
+
|
|
133
|
+
<details>
|
|
134
|
+
<summary>pdm</summary>
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pdm add nonebot_plugin_cardimg
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
</details>
|
|
141
|
+
|
|
142
|
+
<details>
|
|
143
|
+
<summary>poetry</summary>
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
poetry add nonebot_plugin_cardimg
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
</details>
|
|
150
|
+
|
|
151
|
+
<details>
|
|
152
|
+
<summary>conda</summary>
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
conda install nonebot_plugin_cardimg
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
</details>
|
|
159
|
+
|
|
160
|
+
打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分的 `plugins` 项里追加写入
|
|
161
|
+
|
|
162
|
+
```toml
|
|
163
|
+
[tool.nonebot]
|
|
164
|
+
plugins = [
|
|
165
|
+
# ...
|
|
166
|
+
"nonebot_plugin_cardimg"
|
|
167
|
+
]
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
</details>
|
|
171
|
+
|
|
172
|
+
## ⚙️ 配置
|
|
173
|
+
|
|
174
|
+
在 nonebot2 项目的 `.env` 文件中添加下表中的配置
|
|
175
|
+
|
|
176
|
+
| 配置项 | 必填 | 默认值 | 说明 |
|
|
177
|
+
| :--- | :---: | :---: | :--- |
|
|
178
|
+
| `cardimg_use_global_config` | 否 | `False` | 是否使用全局配置作为兜底 |
|
|
179
|
+
| `cardimg_image_format` | 否 | `png` | 全局图片格式:png 或 jpeg |
|
|
180
|
+
| `cardimg_jpeg_quality` | 否 | `85` | 全局 JPEG 质量:1-100 |
|
|
181
|
+
|
|
182
|
+
## 🎉 使用
|
|
183
|
+
|
|
184
|
+
### 基础用法
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from nonebot import require
|
|
188
|
+
require("nonebot_plugin_cardimg")
|
|
189
|
+
from nonebot_plugin_cardimg import render
|
|
190
|
+
|
|
191
|
+
# 渲染小米便签模板
|
|
192
|
+
img_bytes = await render(
|
|
193
|
+
'minote',
|
|
194
|
+
title='标题',
|
|
195
|
+
content='这是正文内容',
|
|
196
|
+
footer='页脚'
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# 渲染简约模板(自动昼夜模式)
|
|
200
|
+
img_bytes = await render(
|
|
201
|
+
'simple',
|
|
202
|
+
title='简约标题',
|
|
203
|
+
content='简约内容'
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
# 渲染帮助文档
|
|
207
|
+
img_bytes = await render(
|
|
208
|
+
'help',
|
|
209
|
+
title='帮助文档',
|
|
210
|
+
items={
|
|
211
|
+
'命令1': '这是命令1的说明',
|
|
212
|
+
'命令2': '这是命令2的说明'
|
|
213
|
+
},
|
|
214
|
+
footer='更多帮助请访问...'
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
# 渲染表格
|
|
218
|
+
img_bytes = await render(
|
|
219
|
+
'table',
|
|
220
|
+
title='排行榜',
|
|
221
|
+
tip='数据更新时间:2026-02-10',
|
|
222
|
+
columns=['排名', '用户', '分数'],
|
|
223
|
+
data=[
|
|
224
|
+
['1', '用户A', '100'],
|
|
225
|
+
['2', '用户B', '95'],
|
|
226
|
+
['3', '用户C', '90']
|
|
227
|
+
]
|
|
228
|
+
)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### 高级用法
|
|
232
|
+
|
|
233
|
+
#### 指定渲染参数
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
img_bytes = await render(
|
|
237
|
+
'simple',
|
|
238
|
+
title='标题',
|
|
239
|
+
content='内容',
|
|
240
|
+
htmlkit_params={
|
|
241
|
+
'max_width': 800,
|
|
242
|
+
'image_format': 'jpeg',
|
|
243
|
+
'jpeg_quality': 90
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### 手动控制昼夜模式
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
# 强制使用夜间模式
|
|
252
|
+
img_bytes = await render(
|
|
253
|
+
'simple',
|
|
254
|
+
title='标题',
|
|
255
|
+
content='内容',
|
|
256
|
+
night_mode=True
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
# 强制使用白天模式
|
|
260
|
+
img_bytes = await render(
|
|
261
|
+
'simple',
|
|
262
|
+
title='标题',
|
|
263
|
+
content='内容',
|
|
264
|
+
night_mode=False
|
|
265
|
+
)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
#### 获取可用模板列表
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
from nonebot_plugin_cardimg import list_templates
|
|
272
|
+
|
|
273
|
+
templates = list_templates()
|
|
274
|
+
print(templates) # ['minote', 'simple', 'ncm_zhusha', 'ncm_card', 'bili', 'help', 'table']
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### 接口方法参考
|
|
278
|
+
|
|
279
|
+
#### `render(template, title="", content="", footer="", htmlkit_params=None, **kwargs)`
|
|
280
|
+
|
|
281
|
+
渲染模板为图片
|
|
282
|
+
|
|
283
|
+
**参数:**
|
|
284
|
+
- `template` (str): 模板名称
|
|
285
|
+
- `title` (str, optional): 标题
|
|
286
|
+
- `content` (str, optional): 正文内容
|
|
287
|
+
- `footer` (str, optional): 页脚
|
|
288
|
+
- `htmlkit_params` (dict, optional): htmlkit 渲染参数
|
|
289
|
+
- `**kwargs`: 模板特定参数
|
|
290
|
+
###### 其中:`template` 是必填项,其他参数根据不同模板需求填写;`htmlkit_params` 是 htmlkit 插件的渲染方法参数,可用来自定义调整渲染尺寸、格式等内容。
|
|
291
|
+
|
|
292
|
+
**返回:**
|
|
293
|
+
- `bytes`: 图片字节数据
|
|
294
|
+
|
|
295
|
+
**模板特定参数:**
|
|
296
|
+
- `simple`/`bili`/`help`/`table`: `night_mode` (bool, optional) - 是否使用夜间模式
|
|
297
|
+
- `help`: `items` (dict) - 帮助项字典
|
|
298
|
+
- `table`: `columns` (list) - 表头列表, `data` (list[list]) - 表格数据, `tip` (str) - 提示文本
|
|
299
|
+
|
|
300
|
+
## 📝 开发
|
|
301
|
+
|
|
302
|
+
### 添加自定义模板
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
from pathlib import Path
|
|
306
|
+
from nonebot_plugin_cardimg import BaseTemplate
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
class MyTemplate(BaseTemplate):
|
|
310
|
+
def __init__(self):
|
|
311
|
+
super().__init__("my_template", Path(__file__).parent / "templates")
|
|
312
|
+
|
|
313
|
+
async def render(self, **kwargs) -> bytes:
|
|
314
|
+
options = kwargs.pop("_render_options", self.get_render_options())
|
|
315
|
+
templates = {
|
|
316
|
+
"title": kwargs.get("title", ""),
|
|
317
|
+
"content": kwargs.get("content", ""),
|
|
318
|
+
}
|
|
319
|
+
return await self.to_pic_template("template.html", templates=templates, **options)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## 📞 联系
|
|
323
|
+
|
|
324
|
+
<div align="center">
|
|
325
|
+
|
|
326
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/qrcode.png" width="200" alt="QQ群">
|
|
327
|
+
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
- 由于技术力和时间有限,本插件可能存在问题和不足,字体自定义以及图片压缩相关问题未能很好解决,欢迎优化或指正(๑˃̵ᴗ˂̵)₊♡
|
|
331
|
+
- 由于技术力和时间有限,本项目的描述和代码排版由AI辅助完成,如有意外的错漏混淆欢迎反馈和指正(๑˃̵ᴗ˂̵)₊♡♡
|
|
332
|
+
- 如有问题或建议,欢迎提交 Issue 或 Pull Request。
|
|
333
|
+
|
|
334
|
+
## 💡 鸣谢
|
|
335
|
+
|
|
336
|
+
- [nonebot-plugin-htmlkit](https://github.com/nonebot/plugin-htmlkit) - HTML 转图片核心库
|
|
337
|
+
- [nonebot-plugin-txt2img](https://github.com/mobyw/nonebot-plugin-txt2img) - 模板样式参考
|
|
338
|
+
- [nonebot-plugin-zxui](https://github.com/HibiKier/nonebot-plugin-zxui) - 模板样式参考
|
|
339
|
+
- [nonebot-plugin-template](https://github.com/lgc-NB2Dev/nonebot-plugin-template) - 插件模板
|
|
340
|
+
|
|
341
|
+
## 📝 更新日志
|
|
342
|
+
|
|
343
|
+
### v0.1.0 (2026-02-10)
|
|
344
|
+
|
|
345
|
+
- 初始版本发布(仅在 Docker 环境下测试通过,暂未解决默认字体替换问题)
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD031 MD033 MD036 MD041 -->
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
<a href="https://v2.nonebot.dev/store">
|
|
6
|
+
<img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
|
|
7
|
+
</a>
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
# nonebot-plugin-cardimg
|
|
14
|
+
|
|
15
|
+
_✨ 基于 nonebot_plugin_htmlkit 渲染的文本转图片模板插件 ✨_
|
|
16
|
+
|
|
17
|
+
<img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="python">
|
|
18
|
+
<a href="https://github.com/astral-sh/uv">
|
|
19
|
+
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
|
|
20
|
+
</a>
|
|
21
|
+
<a href="https://pydantic.dev">
|
|
22
|
+
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/pyd-v1-or-v2.json" alt="Pydantic Version 1 Or 2" >
|
|
23
|
+
</a>
|
|
24
|
+
<a href="./LICENSE">
|
|
25
|
+
<img src="https://img.shields.io/github/license/youlanan/nonebot-plugin-cardimg.svg" alt="license">
|
|
26
|
+
</a>
|
|
27
|
+
<a href="https://pypi.python.org/pypi/nonebot_plugin_cardimg">
|
|
28
|
+
<img src="https://img.shields.io/pypi/v/nonebot_plugin_cardimg.svg" alt="pypi">
|
|
29
|
+
</a>
|
|
30
|
+
|
|
31
|
+
<br />
|
|
32
|
+
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
## 📖 介绍
|
|
36
|
+
|
|
37
|
+
nonebot-plugin-cardimg 是一个基于 nonebot_plugin_htmlkit 的模板化图片渲染插件,为 NoneBot2 插件开发者提供简单易用的文本图片生成功能。
|
|
38
|
+
|
|
39
|
+
### 核心特性
|
|
40
|
+
|
|
41
|
+
- **多种预设模板**:提供 7 种精美模板,覆盖常见使用场景
|
|
42
|
+
- **昼夜模式**:部分模板支持自动/手动切换昼夜主题
|
|
43
|
+
- **随机配色**:部分模板支持随机颜色主题
|
|
44
|
+
- **灵活配置**:支持全局配置和模板特定参数
|
|
45
|
+
- **资源缓存**:内置文件和资源缓存机制,提升性能
|
|
46
|
+
- **易于扩展**:基于抽象基类,方便添加自定义模板
|
|
47
|
+
|
|
48
|
+
### 可用模板
|
|
49
|
+
|
|
50
|
+
| 模板名称 | 描述 | 特性 |
|
|
51
|
+
| :--- | :--- | :--- |
|
|
52
|
+
| `minote` | 小米便签风格 | 背景图+边框+四角装饰 |
|
|
53
|
+
| `simple` | 简约风格 | 纯色背景,支持昼夜模式 |
|
|
54
|
+
| `ncm_zhusha` | 网易云朱砂样式 | 红色背景+白色标题框 |
|
|
55
|
+
| `ncm_card` | 网易云热评卡片 | 音乐评论卡片样式 |
|
|
56
|
+
| `bili` | 哔哩哔哩壁纸 | 支持昼夜模式 |
|
|
57
|
+
| `help` | 帮助文档 | 支持随机颜色主题和昼夜模式 |
|
|
58
|
+
| `table` | 表格展示 | 支持随机颜色主题和昼夜模式 |
|
|
59
|
+
|
|
60
|
+
## 🖼️ 演示效果
|
|
61
|
+
|
|
62
|
+
<details>
|
|
63
|
+
<summary>点击展开查看各模板渲染效果</summary>
|
|
64
|
+
|
|
65
|
+
### 小米便签 (minote)
|
|
66
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/minote-demo.png" width="400">
|
|
67
|
+
|
|
68
|
+
### 简约风格 (simple)
|
|
69
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/simple-demo.png" width="400">
|
|
70
|
+
|
|
71
|
+
### 网易云朱砂 (ncm_zhusha)
|
|
72
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/ncm-zhusha-demo.png" width="400">
|
|
73
|
+
|
|
74
|
+
### 网易云热评卡片 (ncm_card)
|
|
75
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/ncm-card-demo.png" width="400">
|
|
76
|
+
|
|
77
|
+
### 哔哩哔哩壁纸 (bili)
|
|
78
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/bili-demo.png" width="400">
|
|
79
|
+
|
|
80
|
+
### 帮助文档 (help)
|
|
81
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/help-demo.png" width="400">
|
|
82
|
+
|
|
83
|
+
### 表格展示 (table)
|
|
84
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/table-demo.png" width="400">
|
|
85
|
+
|
|
86
|
+
</details>
|
|
87
|
+
|
|
88
|
+
## 安装
|
|
89
|
+
|
|
90
|
+
以下提到的方法 任选**其一** 即可
|
|
91
|
+
|
|
92
|
+
<details open>
|
|
93
|
+
<summary>[推荐] 使用 nb-cli 安装</summary>
|
|
94
|
+
|
|
95
|
+
在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
nb plugin install nonebot_plugin_cardimg
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
</details>
|
|
102
|
+
|
|
103
|
+
<details>
|
|
104
|
+
<summary>使用包管理器安装</summary>
|
|
105
|
+
|
|
106
|
+
在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令
|
|
107
|
+
|
|
108
|
+
<details>
|
|
109
|
+
<summary>pip</summary>
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install nonebot_plugin_cardimg
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
</details>
|
|
116
|
+
|
|
117
|
+
<details>
|
|
118
|
+
<summary>pdm</summary>
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pdm add nonebot_plugin_cardimg
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
</details>
|
|
125
|
+
|
|
126
|
+
<details>
|
|
127
|
+
<summary>poetry</summary>
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
poetry add nonebot_plugin_cardimg
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
</details>
|
|
134
|
+
|
|
135
|
+
<details>
|
|
136
|
+
<summary>conda</summary>
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
conda install nonebot_plugin_cardimg
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
</details>
|
|
143
|
+
|
|
144
|
+
打开 nonebot2 项目根目录下的 `pyproject.toml` 文件, 在 `[tool.nonebot]` 部分的 `plugins` 项里追加写入
|
|
145
|
+
|
|
146
|
+
```toml
|
|
147
|
+
[tool.nonebot]
|
|
148
|
+
plugins = [
|
|
149
|
+
# ...
|
|
150
|
+
"nonebot_plugin_cardimg"
|
|
151
|
+
]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
</details>
|
|
155
|
+
|
|
156
|
+
## ⚙️ 配置
|
|
157
|
+
|
|
158
|
+
在 nonebot2 项目的 `.env` 文件中添加下表中的配置
|
|
159
|
+
|
|
160
|
+
| 配置项 | 必填 | 默认值 | 说明 |
|
|
161
|
+
| :--- | :---: | :---: | :--- |
|
|
162
|
+
| `cardimg_use_global_config` | 否 | `False` | 是否使用全局配置作为兜底 |
|
|
163
|
+
| `cardimg_image_format` | 否 | `png` | 全局图片格式:png 或 jpeg |
|
|
164
|
+
| `cardimg_jpeg_quality` | 否 | `85` | 全局 JPEG 质量:1-100 |
|
|
165
|
+
|
|
166
|
+
## 🎉 使用
|
|
167
|
+
|
|
168
|
+
### 基础用法
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from nonebot import require
|
|
172
|
+
require("nonebot_plugin_cardimg")
|
|
173
|
+
from nonebot_plugin_cardimg import render
|
|
174
|
+
|
|
175
|
+
# 渲染小米便签模板
|
|
176
|
+
img_bytes = await render(
|
|
177
|
+
'minote',
|
|
178
|
+
title='标题',
|
|
179
|
+
content='这是正文内容',
|
|
180
|
+
footer='页脚'
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
# 渲染简约模板(自动昼夜模式)
|
|
184
|
+
img_bytes = await render(
|
|
185
|
+
'simple',
|
|
186
|
+
title='简约标题',
|
|
187
|
+
content='简约内容'
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# 渲染帮助文档
|
|
191
|
+
img_bytes = await render(
|
|
192
|
+
'help',
|
|
193
|
+
title='帮助文档',
|
|
194
|
+
items={
|
|
195
|
+
'命令1': '这是命令1的说明',
|
|
196
|
+
'命令2': '这是命令2的说明'
|
|
197
|
+
},
|
|
198
|
+
footer='更多帮助请访问...'
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
# 渲染表格
|
|
202
|
+
img_bytes = await render(
|
|
203
|
+
'table',
|
|
204
|
+
title='排行榜',
|
|
205
|
+
tip='数据更新时间:2026-02-10',
|
|
206
|
+
columns=['排名', '用户', '分数'],
|
|
207
|
+
data=[
|
|
208
|
+
['1', '用户A', '100'],
|
|
209
|
+
['2', '用户B', '95'],
|
|
210
|
+
['3', '用户C', '90']
|
|
211
|
+
]
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 高级用法
|
|
216
|
+
|
|
217
|
+
#### 指定渲染参数
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
img_bytes = await render(
|
|
221
|
+
'simple',
|
|
222
|
+
title='标题',
|
|
223
|
+
content='内容',
|
|
224
|
+
htmlkit_params={
|
|
225
|
+
'max_width': 800,
|
|
226
|
+
'image_format': 'jpeg',
|
|
227
|
+
'jpeg_quality': 90
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
#### 手动控制昼夜模式
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
# 强制使用夜间模式
|
|
236
|
+
img_bytes = await render(
|
|
237
|
+
'simple',
|
|
238
|
+
title='标题',
|
|
239
|
+
content='内容',
|
|
240
|
+
night_mode=True
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
# 强制使用白天模式
|
|
244
|
+
img_bytes = await render(
|
|
245
|
+
'simple',
|
|
246
|
+
title='标题',
|
|
247
|
+
content='内容',
|
|
248
|
+
night_mode=False
|
|
249
|
+
)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### 获取可用模板列表
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from nonebot_plugin_cardimg import list_templates
|
|
256
|
+
|
|
257
|
+
templates = list_templates()
|
|
258
|
+
print(templates) # ['minote', 'simple', 'ncm_zhusha', 'ncm_card', 'bili', 'help', 'table']
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### 接口方法参考
|
|
262
|
+
|
|
263
|
+
#### `render(template, title="", content="", footer="", htmlkit_params=None, **kwargs)`
|
|
264
|
+
|
|
265
|
+
渲染模板为图片
|
|
266
|
+
|
|
267
|
+
**参数:**
|
|
268
|
+
- `template` (str): 模板名称
|
|
269
|
+
- `title` (str, optional): 标题
|
|
270
|
+
- `content` (str, optional): 正文内容
|
|
271
|
+
- `footer` (str, optional): 页脚
|
|
272
|
+
- `htmlkit_params` (dict, optional): htmlkit 渲染参数
|
|
273
|
+
- `**kwargs`: 模板特定参数
|
|
274
|
+
###### 其中:`template` 是必填项,其他参数根据不同模板需求填写;`htmlkit_params` 是 htmlkit 插件的渲染方法参数,可用来自定义调整渲染尺寸、格式等内容。
|
|
275
|
+
|
|
276
|
+
**返回:**
|
|
277
|
+
- `bytes`: 图片字节数据
|
|
278
|
+
|
|
279
|
+
**模板特定参数:**
|
|
280
|
+
- `simple`/`bili`/`help`/`table`: `night_mode` (bool, optional) - 是否使用夜间模式
|
|
281
|
+
- `help`: `items` (dict) - 帮助项字典
|
|
282
|
+
- `table`: `columns` (list) - 表头列表, `data` (list[list]) - 表格数据, `tip` (str) - 提示文本
|
|
283
|
+
|
|
284
|
+
## 📝 开发
|
|
285
|
+
|
|
286
|
+
### 添加自定义模板
|
|
287
|
+
|
|
288
|
+
```python
|
|
289
|
+
from pathlib import Path
|
|
290
|
+
from nonebot_plugin_cardimg import BaseTemplate
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class MyTemplate(BaseTemplate):
|
|
294
|
+
def __init__(self):
|
|
295
|
+
super().__init__("my_template", Path(__file__).parent / "templates")
|
|
296
|
+
|
|
297
|
+
async def render(self, **kwargs) -> bytes:
|
|
298
|
+
options = kwargs.pop("_render_options", self.get_render_options())
|
|
299
|
+
templates = {
|
|
300
|
+
"title": kwargs.get("title", ""),
|
|
301
|
+
"content": kwargs.get("content", ""),
|
|
302
|
+
}
|
|
303
|
+
return await self.to_pic_template("template.html", templates=templates, **options)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## 📞 联系
|
|
307
|
+
|
|
308
|
+
<div align="center">
|
|
309
|
+
|
|
310
|
+
<img src="https://raw.githubusercontent.com/youlanan/nonebot-plugin-cardimg/main/docs/qrcode.png" width="200" alt="QQ群">
|
|
311
|
+
|
|
312
|
+
</div>
|
|
313
|
+
|
|
314
|
+
- 由于技术力和时间有限,本插件可能存在问题和不足,字体自定义以及图片压缩相关问题未能很好解决,欢迎优化或指正(๑˃̵ᴗ˂̵)₊♡
|
|
315
|
+
- 由于技术力和时间有限,本项目的描述和代码排版由AI辅助完成,如有意外的错漏混淆欢迎反馈和指正(๑˃̵ᴗ˂̵)₊♡♡
|
|
316
|
+
- 如有问题或建议,欢迎提交 Issue 或 Pull Request。
|
|
317
|
+
|
|
318
|
+
## 💡 鸣谢
|
|
319
|
+
|
|
320
|
+
- [nonebot-plugin-htmlkit](https://github.com/nonebot/plugin-htmlkit) - HTML 转图片核心库
|
|
321
|
+
- [nonebot-plugin-txt2img](https://github.com/mobyw/nonebot-plugin-txt2img) - 模板样式参考
|
|
322
|
+
- [nonebot-plugin-zxui](https://github.com/HibiKier/nonebot-plugin-zxui) - 模板样式参考
|
|
323
|
+
- [nonebot-plugin-template](https://github.com/lgc-NB2Dev/nonebot-plugin-template) - 插件模板
|
|
324
|
+
|
|
325
|
+
## 📝 更新日志
|
|
326
|
+
|
|
327
|
+
### v0.1.0 (2026-02-10)
|
|
328
|
+
|
|
329
|
+
- 初始版本发布(仅在 Docker 环境下测试通过,暂未解决默认字体替换问题)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|