框架重构完成!
新框架已经完成对于老框架的完全替代,由原有的固定位置绘制变为了先定义、后执行;将绘图模块化,方便于后期的开发以及开发者调用测试(瘫
具体实现思路如下
设计之初将定义与绘制分开,以模块化的方式绘制整个图片,实现了极大的绘制自由度,能够在一个框架内兼容多套绘图方式甚至是排版。
实现效果图之一(剩下的还在不断开发ing):
总之,新的绘图框架就此诞生,
至此,一锤定音
尘埃,已然落定
框架开发者须知
本文档在于方便开发者进行调试与绘图模块的相关开发。
开发者须知:
本次绘图在调用时候会对部分参数进行修正补全,以减少输入错误造成的问题。
注意:本框架仅接受 列表list 作为输入,其他输入均会抛出相关错误
便捷调用
在bot中,调用此模块仅需要输入如下格式文本即可:
[‘你好,这里是manshuo,欢迎使用本框架’]
[‘data/pictures/cache/manshuo.jpg‘]
[‘你好,这里是manshuo,欢迎使用本框架’, ‘data/pictures/cache/manshuo.jpg‘]
此处的图片地址可以是于Bot工作目录的相对文件地址
,也可以是一个图片链接
,也可以base64
,这些框架均可以识别并返回图片。
注意:此类调用方式默认使用基本绘图,若在测试中需要切换绘图模块或更改绘图方式,我们需要进行更为详细的参数设置,详情见下文。
调用示例
from framework_common.manshuo_draw.manshuo_draw import manshuo_draw
draw_content=[‘你好,这里是manshuo,欢迎使用本框架’,
‘data/pictures/cache/manshuo.jpg‘,
{‘data/pictures/cache/manshuo.jpg‘,‘data/pictures/cache/manshuo.jpg‘},
[url,base64,相对文件地址]
]
img_path=await manshuo_draw(draw_content)
开发者调试
如上文所述,此框架的输入需为一个列表,而列表内部可以是一个集合或者一个字典或者单纯一个字符串,
那么,我们实际需要输入的参数为:
[‘你好,这里是manshuo,欢迎使用本框架’, ‘data/pictures/cache/manshuo.jpg‘]
这样,框架便能在测试时候正确调用本绘图框架了。
框架完整介绍
本框架的输入格式为列表内使用集合,即[{},{},{},{}]
,在集合内会放置相关参数
目前框架内的模块以二级分类为主,示例:text:common
、img:common
其中,一级分类主要有avatar
、text
、img
、others
二级分类当前通用可用模块为common
注意:一级分类仅为便于整体性分类,其绘图模块分布在二级分类中
如上文所述,框架的输入必须是列表下的集合,能够实现上文的便捷输入完全依靠对于输入的检查以及补正,那么我们在这里完全了解一下本框架的完整输入方式:
contents=[
{'type': 'basic_set'}, #此处为基本设置类
{'type': 'backdrop', 'subtype': 'gradient'}, #背景相关设置
{'type': 'text', 'subtype': 'common', 'content': ['这里是manshuo!']} #传入文字
{'type': 'avatar', 'subtype': 'common', 'img':[ ‘data/pictures/cache/manshuo.jpg‘],'content':[{'name': '漫朔_manshuo', 'time': '2025年 05月27日 20:32'}]}, #头像设置
{'type':'img','subtype':'common','img':['framework_common/manshuo_draw/data/cache/manshuo.jpg'] }, #传入图片
]
上图即为本框架的完整输入方式,其中除去 basic_set
类和backdrop
类是对于图像基本设置和背景设置,不实际参与每个框架的绘制,其余即为各个模块的传入参数。
完整调用示例
from framework_common.manshuo_draw.manshuo_draw import manshuo_draw
contents=[
{'type': 'basic_set', 'debug': True,'is_abs_path_convert':True},
{'type': 'backdrop', 'subtype': 'gradient'},
{'type': 'avatar', 'subtype': 'common', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'],
'content':[ {'name': '漫朔_manshuo', 'time': '2025年 05月27日 20:32'}] },
{'type': 'img', 'subtype': 'common', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg','framework_common/manshuo_draw/data/cache/manshuo.jpg','https://www.manshuo.ink/usr/uploads/2025/06/3951553459.jpg'],
'label': ['BiliBili', 'dy', 'manshuo']},
{'type': 'img', 'subtype': 'common_with_des', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'],
'content': ['这里是manshuo[title]!这部分是测manshuo![/title]这manshuo![des]这里是介绍[/des]'] },
]
img_path=await manshuo_draw(draw_content)
层级实现
框架中未传入层级时默认layer
为1,若要绘制不同层级的模块,在每个字典中传入{''layer':int类}
即可,系统会自动递归实现每个模块的层级分布。
完整传入示例
contents=[
{'type': 'basic_set', 'debug': True,'is_abs_path_convert':True},
{'type': 'backdrop', 'subtype': 'gradient'},
{'layer':1,'type': 'avatar', 'subtype': 'common', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'],'upshift':25,
'content':[ {'name': '漫朔_manshuo', 'time': '2025年 05月27日 20:32'}] },
{'layer':3,'type': 'img', 'subtype': 'common', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg','framework_common/manshuo_draw/data/cache/manshuo.jpg','framework_common/manshuo_draw/data/cache/manshuo.jpg'],
'label': ['BiliBili', 'dy', 'manshuo']},
{'layer':2,'type': 'img', 'subtype': 'common_with_des_right', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'],
'content': ['这里是manshuo[title]!这部分是测manshuo![/title]这manshuo![des]这里是介绍[/des]'] },
]
绘图示例
未传入层级参数 | 传入层级参数 |
---|---|
![]() | ![]() |
各模块参数介绍
相关解释在配置文件中也有说明,默认配置文件地址:framework_common/manshuo_draw/defalut_config.yaml
默认配置文件说明
本次的模块为一个二级列表进行读取,在读取基本设置类(basic_set)和背景类(backdrop)时,由于此二模块无二级分类,所以仅读取一级分类作为自己的参数;其余拥有二级分类的模块的将默认配置文件内二级列表和一级列表合并作为自己的参数。
本框架的配置优先级为:传入参数>二级列表>一级列表>图片基本设置
注意:优先级高的配置会覆盖优先级低的相同参数,同一个参数以优先级高的模块决定。
除了每个模块内内置的必须传入键值
must_required_keys
外,其余均为选择性传入
基本设置类(basic_set)
以下是对于图像本体进行设置
参数 | 意义 | 参数 | 意义 |
---|---|---|---|
img_width | 图像默认宽度 | img_height | 图像默认最大长度 |
padding_left_common | 层级的左间距 | padding_up_common | 层级的上间距 |
is_crop_front | 是否对图片进行裁剪 | is_rounded_corners_front | 是否对模块进行圆角处理前置开关 |
is_ shadow _front: | 是否对模块进行阴影处理前置开关 | is_stroke_front | 是否对模块进行描边处理前置开关 |
img_path_save | 若有图片保存需求,则会将文件保存在此处,基于‘Eridanus’文件夹 | debug | 开启后控制台会输出相应处理过程 |
config_path | 默认配置文件地址 | is_abs_path_convert | 将文件路径转换为绝对路径(默认关闭,可能会有bug,但建议开发者打开以便于测试) |
注意: is_abs_path_convert
此处同时对传入的img路径进行转换,绝对路径初始值为‘Eridanus’,即bot所在文件夹
以下是对于层级的部分全局设置
参数 | 意义 | 参数 | 意义 |
---|---|---|---|
layer | 默认的层级 | padding_up_layer | 层级中各模块间的间隔 |
backdrop_mode | 可选模式为单色:one_color 、无色:no_color 、渐变色:gradient | backdrop_color | 背景颜色 |
is_rounded_corners_layer | 是否对层级进行圆角处理 | rounded_corners_radius | 层级的圆角弧度 |
is_stroke_layer | 是否对层级进行描边处理 | stroke_layer_radius | 描边的圆角弧度 |
stroke_layer_width | 描边的圆角宽度 | is_shadow_layer | 是否对层级进行阴影处理 |
shadow_offset_layer | 阴影的偏移量 | shadow_opacity_layer | 阴影的透明度 |
blur_radius_layer: | 阴影模糊半径 | |
参数在默认配置文件中都有说明,请自行查看,谢谢
文字类(text)
参数 | 意义 | 参数 | 意义 |
---|---|---|---|
sapcing | 文字间的间隔 | 无 | 无 |
- 传入的文字默认为common类。
- 面对使用不同字体、颜色、大小的需求,我们可以使用[tag]content[/tag]来更换,其中
tag
为不同字体的类型。 - 可以在配置文件自行添加不同的字体类型,系统会自动检测tag并调用,键值为
font_{tag}
、font_{tag}_size
、font_{tag}_color
- 当前内置字体共有:common、tag、des、title
传入内容示例:
{'type': 'text', 'subtype': 'common', 'content': ['这里是manshuo[title]这部分是测manshuo![/title]这manshuo![des]这里是介绍[/des]'] },
图像类(img)
参数 | 意义 | 参数 | 意义 |
---|---|---|---|
label | 默认的label内容 | label_color | 默认label颜色 |
is_rounded_corners_label | 是否对标签进行圆角处理 | rounded_label_radius | 圆角处理半径 |
is_stroke_label | 是否对标签进行描边处理 | stroke_label_radius | 描边的圆角弧度 |
stroke_label_width | 描边的圆角宽度 | is_shadow_label | 是否对标签进行阴影处理 |
shadow_offset_label | 阴影的偏移量 | shadow_opacity_label | 阴影的透明度 |
blur_radius_label | 阴影模糊半径 | must_required_keys | 必须传入的键值 |
number_per_row | 每行图片个数,默认即为九宫格,可自定义 | is_crop | 是否裁剪 |
label
可不传入,不传入即视为不绘制label- 若仅绘制第二个label,第一个label传入‘’即可,以逗号分开
number_per_row
与is_crop
不传入时均为default
,此时系统会根据传入的图片数量自行设置
普通绘制(common)
- 无额外参数
传入内容示例:
{'type': 'img', 'subtype': 'common', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg','framework_common/manshuo_draw/data/cache/manshuo.jpg','framework_common/manshuo_draw/data/cache/manshuo.jpg'], 'label': ['BiliBili', 'dy', 'manshuo']},
带介绍绘图(common_with_des)
参数 | 意义 | 参数 | 意义 |
---|---|---|---|
description_color | 放置介绍区域的颜色 | max_des_length | 简介区域最大长度 |
传入内容示例:
{'type': 'img', 'subtype': 'common_with_des', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'], 'content': ['这里是manshuo[title]!这部分是测manshuo![/title]这manshuo![des]这里是介绍[/des]'] },
带右侧介绍绘图(common_with_des_right)
参数 | 意义 | 参数 | 意义 |
---|---|---|---|
description_color | 放置介绍区域的颜色 | 无 | 无 |
传入内容示例:
{'type': 'img', 'subtype': 'common_with_des_right', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'], 'content': ['这里是manshuo[title]!这部分是测manshuo![/title]这manshuo![des]这里是介绍[/des]'] },
绘图示例(img类)
common | common_with_des | common_with_des_right |
---|---|---|
![]() ![]() | ![]() | ![]() |
头像类(avatar)
参数 | 意义 | 参数 | 意义 |
---|---|---|---|
background | 背景图片 | right_icon | 右侧图标图片 |
type_software | 图标类型,此处会自动设置背景图片和右侧图标 | software_list | 图标存储的列表 |
is_shadow_font | 文字是否添加阴影 | is_name | 是否在右侧绘制文字 |
avatar_size | 头像大小 | padding | 头像至左侧距离 |
padding_up_bottom | 上下与其他模块间的距离 | upshift | 上偏移量 |
- 当检测到使用背景图片后,部分键值将会被自动设置
- 上偏移量(
upshift
)是将本模块直接上移,意在覆盖模块间的自动间距以实现无缝衔接
普通绘制(common)
- 无额外参数
传入内容示例:
{'type': 'avatar', 'subtype': 'common', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'],'type_software':'bilibili' 'content':[ {'name': '漫朔_manshuo', 'time': '2025年 05月27日 20:32'}] },
绘图示例(avatar类)
common | common(有背景) |
---|---|
![]() | ![]() |
Comments | NOTHING