Skip to content

Commit

Permalink
🎨 优化工具类代码
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Nov 21, 2024
1 parent 03d8b3a commit af8f58b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 22 additions & 3 deletions zhenxun/utils/_build_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ async def auto_paste(
"""
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:
Expand All @@ -168,12 +169,22 @@ async def auto_paste(
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
Expand Down Expand Up @@ -719,3 +730,11 @@ def tobytes(self) -> bytes:
bytes: bytes
"""
return self.markImg.tobytes()

def copy(self) -> "BuildImage":
"""复制
返回:
BuildImage: Self
"""
return BuildImage.open(self.pic2bytes())
2 changes: 2 additions & 0 deletions zhenxun/utils/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def alc_forward_msg(
_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))
)
Expand Down

0 comments on commit af8f58b

Please sign in to comment.