【问题标题】:Python - Pillow rounded rectangle not workingPython - 枕头圆角矩形不起作用
【发布时间】:2021-08-03 02:18:03
【问题描述】:

我尝试为我的 Discord Bot 创建排名卡。但是经验条不会正确舍入。 我不知道该怎么办。这是我的代码:

def draw(self, user: str, rank: str, level: str, xp: str, needed_xp: str, profile_bytes: BytesIO) -> BytesIO:
        
        profile_bytes = Image.open(profile_bytes)
        im = Image.new('RGBA', (800, 200), (44, 44, 44, 255))

        im_draw = ImageDraw.Draw(im)
        im_draw.text((154, 5), user, font=self.font, fill=(255, 255, 255, 255))

        rank_text = f'Rank:  #{rank}'
        im_draw.text((154, 37), rank_text, font=self.medium_font, fill=(255, 255, 255, 255))

        xp_text = f'Level: {level}'
        im_draw.text((154, 62), xp_text, font=self.small_font, fill=(255, 255, 255, 255))

        xp_text = f'Experience: {xp}/{needed_xp}'
        im_draw.text((154, 87), xp_text, font=self.small_font, fill=(255, 255, 255, 255))

        im_draw.rounded_rectangle((40, 180, 440, 150), fill=(64, 64, 64, 255), outline=(92, 23, 47, 255), width=3, radius=15)
        
        length = 40 + int(xp)/int(needed_xp)*400
        im_draw.rounded_rectangle((40, 180, length, 150), fill=(221, 221, 221, 255), outline=(92, 23, 47, 255), width=3, radius=15)
        
        im.paste(profile_bytes, (10, 10))

        im.show()

但它只是创建了这个:https://imgur.com/TWEbxHh

级别栏看起来像是被切断了。我能做什么?

【问题讨论】:

    标签: python image python-imaging-library


    【解决方案1】:

    问题是您的 y 坐标顺序错误。它试图使曲线从第一个 Y 下降并从第二个 Y 上升,从而产生您看到的结果。改为:

    im_draw.rounded_rectangle((40, 150, 440, 180), ...
    and
    im_draw.rounded_rectangle((40, 150, length, 180), ...
    

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多