Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用PIL在图片上绘制特殊文本_Python_Python 3.x_Python Imaging Library_Discord.py - Fatal编程技术网

Python 使用PIL在图片上绘制特殊文本

Python 使用PIL在图片上绘制特殊文本,python,python-3.x,python-imaging-library,discord.py,Python,Python 3.x,Python Imaging Library,Discord.py,我只是想在我的Discord机器人中使用PIL和Python3.8.6在图片上写一些文字,虽然有一个成员加入了,但它没有正确显示,这是我的代码和结果图片 background = Image.open("./photos/Sans titre 1.png").convert("RGBA") basewidth = 227 img = Image.open(BytesIO(response.content)).convert(&quo

我只是想在我的Discord机器人中使用PIL和Python3.8.6在图片上写一些文字,虽然有一个成员加入了,但它没有正确显示,这是我的代码和结果图片

    background = Image.open("./photos/Sans titre 1.png").convert("RGBA")
    basewidth = 227
    img = Image.open(BytesIO(response.content)).convert("RGBA")
    wpercent = (basewidth/float(img.size[0]))
    hsize = int((float(img.size[1])*float(wpercent)))
    img = img.resize((basewidth,hsize), Image.ANTIALIAS)
    cercle = Image.open("./photos/cercle_orange.png").convert("RGBA")
    img_w, img_h = img.size
    cr_w,cr_h = cercle.size
    # make a blank image for the text, initialized to transparent text color
    txt = Image.new("RGBA", background.size, (255,255,255,0))
    msg = "WELCOME"
    
    new_member = u"{}#{}".format(member.name,member.discriminator)
    fnt = ImageFont.truetype("./fonts/DejaVuSans.ttf", 80)
    fntname = ImageFont.truetype("./fonts/DejaVuSans.ttf",50)
    # get a drawing context
    d = ImageDraw.Draw(txt)
    bg_w, bg_h = background.size
    offset = ((bg_w - img_w) // 2, (bg_h - img_h) // 2)
    w, h = d.textsize(msg,font=fnt)
    w2, h2 = d.textsize(new_member,font=fntname)
    d.text(((bg_w-w)/2,((bg_h-h)/2)+160), msg, font=fnt, fill='#FFAA39')
    d.text((((bg_w-w2)/2),((bg_h-h2)/2)+220), new_member, font=fntname, fill=(255,255,255,255))
    background.paste(profile, offset, profile)
我的机器人欢迎图片不和谐


我已经在搜索如何将文本转换为unicode,但它不起作用,但是我更改了我在bot代码中使用的字体,我希望它显示名称。这种显示方块的行为通常发生在字体无法呈现指定字符时,这可能意味着字体已损坏,或者只是指定的字体缺少这些特定字符的标志符号。最常用的字体有广泛的字形,包括常用的脚本(拉丁语、希腊语、希伯来语、西里尔语、阿拉伯语等)


您可能想尝试更改字体,看看它是否有效,如果有效,那么问题在于字体,您可能想尝试查找该字体的另一个来源,看看它是否包含必要的字形,或者直接更改字体。

我尝试通过更改字体来解决此问题,我尝试了太多的字体,从到多种类型,但对我无效,而且我没有找到包含字形的源代码。你应该继续尝试找到包含这些字形的字体,它们并不常见。