scp.py 文件源码

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

项目:nyx 作者: Cappycot 项目源码 文件源码
def ohno(self, ctx, *words):
        """Generates your very own SCP-3078 cognitohazardous shitpost.

        e.g. "when you inhale the devil's mary jane smoke"
        """
        # Damn I tried to imitate the SCP-3078 instances but they don't follow
        # the same layout in different imitations, so the first one is followed
        # the best here.
        font = ImageFont.truetype(join(folder, "Calibri.ttf"), 19)
        append = None
        width = 256
        x_start = 22
        y_cur = 13
        y_pad = 3
        image = Image.open(join(folder, "SCP-3078.png"))
        draw = ImageDraw.Draw(image)
        for word in words:
            if append is None:
                append = word
            else:
                prev = append
                append = " ".join([append, word])
                w, h = draw.textsize(append, font=font)
                if w > width:
                    append = word
                    draw.text((x_start, y_cur), prev, fill=(0, 0, 0),
                              font=font)
                    y_cur += h + y_pad
        if append is not None:
            draw.text((x_start, y_cur), append, fill=(0, 0, 0), font=font)
        image_bytes = BytesIO()
        image.save(image_bytes, format="png")
        image_bytes.seek(0)
        await ctx.send(file=File(image_bytes, filename="SCP-3078.png"))
        image_bytes.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号