显示正方形而不是Python PIL中的某些特殊字符

2024-10-03 13:16:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试了很多方法,但都没有解决我的问题。 我尝试过的:更改字体,将文件保存为UTF-8,等等。。。 我的代码:

    img = Image.open("WlcImageThings/bg.png")
    txtUser_font = ImageFont.truetype('WlcImageThings/DejaVuSans.ttf', 25)
    eimg = ImageDraw.Draw(img)
    eimg.text((25,50), u'𝗺𝗮𝗱', (237, 230, 211), font=txtUser_font, stroke_width=2, stroke_fill=(0, 0, 0))
    img.save("WlcImageThings/result.png", quality=100)
    file = discord.File("WlcImageThings/result.png", filename="result.png")
    await channel.send(file=file)

结果: Result


Tags: 文件方法代码imageimgstrokepng字体
1条回答
网友
1楼 · 发布于 2024-10-03 13:16:58

对不起,我现在明白了。问题是DejaVuSans不包含这些代码点。我尝试了其他Unicode代码点(比如线描集),这些都很好。您需要找到包含这些字符的字体

相关问题 更多 >