需求
需求就是一批图片,在固定位置加上相应文字。为查看折线图的人在一张图片上提供足够的信息。
代码
其实只需要寥寥数行代码就能实现,
而且支持调整字体、大小、颜色
from PIL import Image,ImageDraw,ImageFont # pip install pillow
fp = '图片.png'
img = Image.open(fp)
draw = ImageDraw.Draw(img)
ttfront = ImageFont.truetype('msyh.ttc', 14) #字体,大小
content = '''正文'''
draw.text((976, 260),content,fill=(0,25,25), font=ttfront)#文字位置,正文内容,文字RGB颜色,字体
img.save(fp)
print('执行完毕')