update v0.0.9.0

This commit is contained in:
HibiKier
2022-01-16 14:52:50 +08:00
parent 30b56583bd
commit 4cb91b47e6
53 changed files with 717 additions and 488 deletions
+32 -23
View File
@@ -168,6 +168,17 @@ async def text2image(
:param font_color: 普通字体颜色
:param padding: 文本外边距,元组类型时为 (上,左,下,右)
"""
pw = ph = top_padding = left_padding = 0
if padding:
if isinstance(padding, int):
pw = padding * 2
ph = padding * 2
top_padding = left_padding = padding
elif isinstance(padding, tuple):
pw = padding[0] + padding[2]
ph = padding[1] + padding[3]
top_padding = padding[0]
left_padding = padding[1]
if auto_parse and re.search(r"<f(.*)>(.*)</f>", text):
_data = []
new_text = ""
@@ -277,24 +288,13 @@ async def text2image(
for img in image_list:
height += img.h
width = width if width > img.w else img.w
top_padding = left_padding = 0
if padding:
if isinstance(padding, int):
width += padding * 2
height += padding * 2
top_padding = left_padding = padding
elif isinstance(padding, tuple):
width += padding[0] + padding[2]
height += padding[1] + padding[3]
top_padding = padding[0]
left_padding = padding[1]
width += pw
height += ph
A = BuildImage(width + left_padding, height + top_padding, color=color)
current_height = top_padding
for img in image_list:
await A.apaste(img, (left_padding, current_height), True)
current_height += img.h
# A.show()
return A.pic2bs4()
else:
width = 0
height = 0
@@ -303,10 +303,18 @@ async def text2image(
w, h = _tmp.getsize(x)
height += h
width = width if width > w else w
A = BuildImage(width, height, font_size=font_size, color=color)
await A.atext((0, 0), text, font_color)
# A.show()
return A.pic2bs4()
width += pw
height += ph
A = BuildImage(
width + left_padding,
height + top_padding,
font_size=font_size,
color=color,
font=font,
)
await A.atext((left_padding, top_padding), text, font_color)
# A.show()
return A.pic2bs4()
class BuildImage:
@@ -354,6 +362,7 @@ class BuildImage:
self.font = ImageFont.truetype(FONT_PATH + font, int(font_size))
if not plain_text and not color:
color = (255, 255, 255)
self.background = background
if not background:
if plain_text:
if not color:
@@ -589,7 +598,7 @@ class BuildImage:
pos = (w, h)
self.draw.text(pos, text, fill=fill, font=self.font)
async def asave(self, path: Union[str, Path]):
async def asave(self, path: Optional[Union[str, Path]] = None):
"""
说明:
异步 保存图片
@@ -598,15 +607,15 @@ class BuildImage:
"""
await self.loop.run_in_executor(None, self.save, path)
def save(self, path: Union[str, Path]):
def save(self, path: Optional[Union[str, Path]] = None):
"""
说明:
保存图片
参数:
:param path: 图片路径
"""
if isinstance(path, Path):
path = path.absolute()
if not path:
path = self.background
self.markImg.save(path)
def show(self):
@@ -847,8 +856,8 @@ class BuildImage:
for j in range(r2):
lx = abs(i - r) # 到圆心距离的横坐标
ly = abs(j - r) # 到圆心距离的纵坐标
l = (pow(lx, 2) + pow(ly, 2)) ** 0.5 # 三角函数 半径
if l < r3:
l_ = (pow(lx, 2) + pow(ly, 2)) ** 0.5 # 三角函数 半径
if l_ < r3:
pim_b[i - (r - r3), j - (r - r3)] = pim_a[i, j]
self.markImg = imb
+1 -1
View File
@@ -59,7 +59,7 @@ class AdminManager(StaticData):
def get_plugin_module(self, cmd: str) -> Optional[str]:
"""
根据 cmd 获取功能 module
根据 cmd 获取功能 modules
:param cmd: 命令
"""
for key in self._data.keys():
+16 -16
View File
@@ -18,7 +18,7 @@
#
# def add_plugin_config(
# self,
# module: str,
# modules: str,
# key: str,
# value: str,
# help_: Optional[str] = None,
@@ -26,39 +26,39 @@
# ):
# """
# 为插件添加一个配置
# :param module: 模块
# :param modules: 模块
# :param key: 键
# :param value: 值
# :param help_: 配置注解
# :param default_value: 默认值
# """
# if self._data.get(module) is None:
# self._data[module] = {}
# self._data[module][key] = {
# if self._data.get(modules) is None:
# self._data[modules] = {}
# self._data[modules][key] = {
# "value": value,
# "help": help_,
# "default_value": default_value,
# }
#
# def remove_plugin_config(self, module: str):
# def remove_plugin_config(self, modules: str):
# """
# 为插件删除一个配置
# :param module: 模块名
# :param modules: 模块名
# """
# if module in self._data.keys():
# del self._data[module]
# if modules in self._data.keys():
# del self._data[modules]
#
# def get_config(self, module: str, key: str) -> Optional[Any]:
# def get_config(self, modules: str, key: str) -> Optional[Any]:
# """
# 获取指定配置值
# :param module: 模块名
# :param modules: 模块名
# :param key: 配置名称
# """
# if module in self._data.keys():
# if self._data[module].get(key):
# if self._data[module][key]["value"] is None:
# return self._data[module][key]["default_value"]
# return self._data[module][key]["value"]
# if modules in self._data.keys():
# if self._data[modules].get(key):
# if self._data[modules][key]["value"] is None:
# return self._data[modules][key]["default_value"]
# return self._data[modules][key]["value"]
# return None
#
#
+1 -1
View File
@@ -86,7 +86,7 @@ class Plugins2settingsManager(StaticData):
self, cmd: str, is_all: bool = False
) -> Union[str, List[str]]:
"""
根据 cmd 获取功能 module
根据 cmd 获取功能 modules
:param cmd: 命令
:param is_all: 获取全部包含cmd的模块
"""
+1 -1
View File
@@ -208,7 +208,7 @@ def get_message_at(data: str) -> List[int]:
return []
def get_message_imgs(data: str) -> List[str]:
def get_message_img(data: str) -> List[str]:
"""
说明:
获取消息中所有的 图片 的链接