images.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Cassandra 作者: Avinch 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号