def _quilt(self, avatars):
"""
Makes a quilt of avatars of avatars that tries to be as square as possible
"""
xbound = math.ceil(math.sqrt(len(avatars)))
ybound = math.ceil(len(avatars) / xbound)
size = int(2520 / xbound)
base = Image.new(mode='RGBA', size=(xbound * size, ybound * size), color=(0, 0, 0, 0))
x, y = 0, 0
for avatar in avatars:
im = Image.open(avatar)
base.paste(im.resize((size, size), resample=Image.BILINEAR), box=(x * size, y * size))
if x < xbound - 1:
x += 1
else:
x = 0
y += 1
buffer = BytesIO()
base.save(buffer, 'png')
buffer.seek(0)
return discord.File(buffer, filename='quilt.png')
评论列表
文章目录