python3里面的图片处理库 pillow
在python2下用pil,而在python3下可以安装pillow
功能,在图片上加上几个字
#coding: utf-8
myPath = "./"
fontPath = "./"
inputFile = "img.jpg"
outputFile = "output.jpg"
#图片的基本参数获取
try:
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
except ImportError:
import Image, ImageDraw, ImageFont, ImageEnhance
img = Image.open('img.jpg')
draw = ImageDraw.Draw(img)
fontsize = min(img.size)/4
print(fontsize)
#用黑体可以写中文,如果是英文字体发现不能显示中文
myfont = ImageFont.truetype('C:/windows/fonts/simhei.ttf', size = int(fontsize))
fillcolor = "#ff0000"
width, height = img.size
draw.text((0,img.size[0]-int(fontsize)),"你好a", font=myfont, fill=fillcolor)
img.save(outputFile,'jpeg')
文章对您有帮助,开心可以打赏我,金额随意,欢迎来赏!
需要电子方面开发板/传感器/模块等硬件可以到我的淘宝店逛逛