python 在图片上添加文字

1.导入包

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

2.设置字体格式,如果没有,也可以不设置

font = ImageFont.truetype(r"E:\msyh.ttc", 20)  #参数1:字体文件路径
font = ImageFont.truetype(size=20)

3.打开底版图片

imageFilePath = "new_image.png"
tp = Image.open(imageFilePath)

4.在图片上添加文字

draw = ImageDraw.Draw(tp)

# (参数1:x,y坐标  2:添加的文字   3:颜色    4:字体)
draw.text((273, 2), "测试文字", (255, 255, 0), font=font)

tp.save("new_Image.png") 		# 保存文件


python 在图片上添加文字

发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章