需要pip install pillow
from PIL import Image,ImageDraw,ImageFont
import os
if __name__ == '__main__':
images_dir = "D:/pycodes/python_image_processing/9781789343731_Code/images"
file_name = "parrot.png"
file_path = os.path.join(images_dir,file_name)
im = Image.open(file_path)
# 添加文本
draw = ImageDraw.Draw(im)
font = ImageFont.truetype("YaMingTiC-2.ttf",23)
draw.text((20,10),'至神大道鹦鹉皇帝图',
font=font,fill=(0,0,0))
del draw
im.show()
结果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)