用python给图片添加文字(水印)

题目来源于:Python 练习册,每天一个小程序 第0000题

代码如下:

#-*- coding:utf-8 -*-
import PIL
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

#设置所使用的字体
font = ImageFont.truetype("C:WindowsFontsArial.ttf", 24)

#打开图片
imageFile = "3.jpg"
im1 = Image.open(imageFile)

#画图
draw = ImageDraw.Draw(im1)
draw.text((160, 0), "4", (255, 0, 0), font=font)    #设置文字位置/内容/颜色/字体
draw = ImageDraw.Draw(im1)                          #Just draw it!

#另存图片
im1.save("target.jpg")
原文地址:https://www.cnblogs.com/wuzhiblog/p/6535543.html