mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
🎨 优化工具类代码
This commit is contained in:
parent
03d8b3aafd
commit
af8f58b61e
@ -156,7 +156,8 @@ class BuildImage:
|
||||
"""
|
||||
if not img_list:
|
||||
raise ValueError("贴图类别为空...")
|
||||
width, height = img_list[0].size
|
||||
width = max(img.size[0] for img in img_list)
|
||||
height = max(img.size[1] for img in img_list)
|
||||
background_width = width * row + space * (row - 1) + padding * 2
|
||||
row_count = math.ceil(len(img_list) / row)
|
||||
if row_count == 1:
|
||||
@ -168,12 +169,22 @@ class BuildImage:
|
||||
background_width, background_height, color=color, background=background
|
||||
)
|
||||
_cur_width, _cur_height = padding, padding
|
||||
for img in img_list:
|
||||
row_num = 0
|
||||
for i in range(len(img_list)):
|
||||
row_num += 1
|
||||
img: Self | tImage = img_list[i]
|
||||
await background_image.paste(img, (_cur_width, _cur_height))
|
||||
_cur_width += space + img.width
|
||||
if _cur_width + padding >= background_image.width:
|
||||
next_image_width = 0
|
||||
if i != len(img_list) - 1:
|
||||
next_image_width = img_list[i + 1].width
|
||||
if (
|
||||
row_num == row
|
||||
or _cur_width + padding + next_image_width >= background_image.width + 1
|
||||
):
|
||||
_cur_height += space + img.height
|
||||
_cur_width = padding
|
||||
row_num = 0
|
||||
return background_image
|
||||
|
||||
@classmethod
|
||||
@ -719,3 +730,11 @@ class BuildImage:
|
||||
bytes: bytes
|
||||
"""
|
||||
return self.markImg.tobytes()
|
||||
|
||||
def copy(self) -> "BuildImage":
|
||||
"""复制
|
||||
|
||||
返回:
|
||||
BuildImage: Self
|
||||
"""
|
||||
return BuildImage.open(self.pic2bytes())
|
||||
|
||||
@ -124,6 +124,8 @@ class MessageUtils:
|
||||
_message[i] = Image(
|
||||
raw=BuildImage.open(_message[i]).pic2bytes()
|
||||
)
|
||||
elif isinstance(_message[i], BuildImage):
|
||||
_message[i] = Image(raw=_message[i].pic2bytes())
|
||||
node_list.append(
|
||||
CustomNode(uid=uin, name=name, content=UniMessage(_message))
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user