python给图片添加字符

来源:互联网 发布:自动化交易编程设计 编辑:程序博客网 时间:2024/05/29 15:54

以后制作表情包都不用ps了,用python就行。代码很简单:

#coding=utf-8'''python图像处理库PIL'''import PILfrom PIL import ImageFontfrom PIL import Imagefrom PIL import ImageDraw#打开底板图片imageFile="base.jpg"im1=Image.open(imageFile)font=ImageFont.truetype('1.ttf',36)#在图片上添加文字draw=ImageDraw.Draw(im1)#xSize,ySize=draw.sizedraw.text((0,0),unicode('哈登','utf-8'),(255,0,0),font=font)#保存im1.show()im1.save("target.jpg")