Skip to Content
EridanusEridanus
框架开发公共服务

绘图框架(manshuo_draw)

使用模块化绘图框架 manshuo_draw 进行声明式图文排版、多层级布局与长图渲染

manshuo_draw 采用“先定义、后执行”的模块化绘图架构,将配置定义与实际渲染分离,支持在同一个框架内组合多种排版与绘图方式。

绘图框架

开发者须知

框架在调用时会对部分输入参数进行修正补全,以减少参数遗漏造成的报错。

本框架仅接受 list(列表)作为输入,传入其他类型会抛出相关错误。

便捷调用

在 Bot 中调用此模块时,可直接传入包含文本或图片的列表:

[‘你好,这里是manshuo,欢迎使用本框架’]
[‘data/pictures/cache/manshuo.jpg‘]
[‘你好,这里是manshuo,欢迎使用本框架’, ‘data/pictures/cache/manshuo.jpg‘]

图片地址支持基于 Bot 工作目录的相对文件路径、图片 URL 或 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':[f"[name]漫朔_manshuo[/name]\n[time]2025年 05月27日 20:32[/time]"]}, #头像设置
{'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':[ f"[name]漫朔_manshuo[/name]\n[time]2025年 05月27日 20:32[/time]"] },

        {'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':[ f"[name]漫朔_manshuo[/name]\n[time]2025年 05月27日 20:32[/time]"] },

        {'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将文件路径转换为绝对路径(默认关闭,建议调试时开启)
max_num_of_columns多列绘制时的最大列数,防止无限递归proxy代理端口
auto_line_change是否实现自动换行,关闭则不判断文本直接粘贴version绘图版本

is_abs_path_convert 会同时转换传入的 img 路径,绝对路径基准为 Eridanus(即 Bot 所在文件夹)。

层级全局设置

参数意义参数意义
layer默认的层级padding_up_layer层级中各模块间的间隔
backdrop_mode可选模式:单色 one_color、无色 no_color、渐变色 gradientbackdrop_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阴影模糊半径

背景类(backdrop)

背景的二级分类分为 one_color、gradient、img(对应单色、渐变色、图片),各有独立配置项:

  • one_color:color(单色背景的颜色)
  • gradient:left_color(左上角渐变颜色)、right_color(右下角渐变颜色)
  • img:background(背景图片路径或 URL)、is_blurred(背景是否模糊化)、is_shadow(背景是否添加阴影)

文字类(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是否裁剪
magnification_img图片占该模块空间,以倍数方式呈现
  • 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]'] },

带左侧介绍绘图(common_with_des_left)

参数与 common_with_des_right 一致。

绘图示例(img 类)

commoncommon_with_descommon_with_des_right
commoncommoncommon_with_descommon_with_des_right

头像类(avatar)

参数意义参数意义
background背景图片right_icon右侧图标图片
type_software图标类型,会自动设置背景图片和右侧图标software_list图标存储的列表
is_shadow_font文字是否添加阴影is_name是否在右侧绘制文字
avatar_size头像大小padding头像至左侧距离
padding_up_bottom上下与其他模块间的距离upshift_extra上偏移量
padding_up_font头像右侧文字距离上部的距离judge_flag判断头像背景处理方式:'common' 平铺样式、'list' 列表样式、'default' 自动判断
is_blurred是否对背景图片进行模糊is_shadow是否对背景图片加上阴影
number_per_row默认 1,可指定每行头像数量avatar_backdrop_color放置介绍区域的颜色
auto_line_change是否实现自动换行,关闭则不判断文本直接粘贴
  • 检测到使用背景图片后,部分键值会自动设置。
  • upshift_extra(上偏移量)会将当前模块整体上移,用于覆盖模块间的自动间距以实现无缝衔接。

普通绘制(common)

无额外参数。

        {'type': 'avatar', 'subtype': 'common', 'img': ['framework_common/manshuo_draw/data/cache/manshuo.jpg'],'type_software':'bilibili'
         'content':[ f"[name]漫朔_manshuo[/name]\n[time]2025年 05月27日 20:32[/time]"] },

绘图示例(avatar 类)

commoncommon(有背景)
commoncommon(有背景)

On this page