python 图片上添加中文文字

1.在 “C:\Windows\Fonts\Microsoft YaHei UI”目录下搜索找到 “msyh.ttc”,复制到工程目录

2.编写代码:

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont


font = ImageFont.truetype("F:/glf_money_date_test/font/msyh.ttc", 18)

img_path = 'tmp.jpg'

image = Image.open(img_path)

draw_ = ImageDraw.Draw(image)

text = '你好'

draw_.text((0, 0), text, (0, 0, 0), font=font)

draw_ = ImageDraw.Draw(image)

re_path = 'test.jpg'

im1.save(re_path)

 

你可能感兴趣的:(python)