diff --git a/zhenxun/utils/_build_image.py b/zhenxun/utils/_build_image.py index 7f353d4b..3fdf4600 100644 --- a/zhenxun/utils/_build_image.py +++ b/zhenxun/utils/_build_image.py @@ -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()) diff --git a/zhenxun/utils/message.py b/zhenxun/utils/message.py index 0834c14d..c17d14f1 100644 --- a/zhenxun/utils/message.py +++ b/zhenxun/utils/message.py @@ -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)) )