我有这段代码,它给出了包含对应text2write变量的png文件。
# -*- coding: utf-8 -*-
# text 2 img
from PIL import Image, ImageDraw, ImageFont
bg={
'white':(255, 255, 255),
'black':(0,0,0),
'black':'black',
'grey':(125,125,125)
}
ftsize=30
# text2write
# 見五口
text=u"見五口"
# dynamic bg size by text size
bgsize=(int((ftsize*len(text))/2+ftsize),ftsize*2) #x,y
img = Image.new('RGB', bgsize, color = bg['grey'])
# usethis if py2
fnt = ImageFont.truetype('/home/user/.fonts/arial.ttf', ftsize)
# fnt = "arial"
d = ImageDraw.Draw(img)
d.text((10,10), text,
font=fnt, fill=bg['black'])
img.save('output.png')给出此输出。

我确实期待着見五口chars在巴新的展示。
发布于 2019-10-14 22:45:05
当你把文本放到图片上时,试试这个
text.encode("utf-8")Edit2
fnt=ImageFont.truetype("/Library/Fonts/Arial Unicode.ttf",14)
draw.text((50, 50), text, font=font)https://stackoverflow.com/questions/58379057
复制相似问题