from PIL import Image,ImageFont,ImageDraw
import sys
reload(sys) #必须要reload
sys.setdefaultencoding('utf-8') #字符编码改为utf8
headPath=r""
#头像图片路径
output=r""
#处理后输出路径
fontPath=r""
#字体路径
headFile="" #头像文件
outFile="" #输出文件
#打开图片建立画布
image=Image.open(headPath+headFile,r)
draw=ImageDraw.Draw(image)
#由图片大小确定字体大小
fontsize=min(image.size)/4
#增加文字
fontobj=ImageFont.truetype(font=fontPath+"AdobeHeisistd-Regular.otf",size=fontsize,index=0,encoding=",filename=None)#
"""
"""
from PIL import Image,ImageFont,ImageDraw#从PIL库导入所需模块
import sys
reload(sys) #必须要reload
sys.setdefaultencoding('utf-8')#字符编码改为utf8
headPath=r"E:\\vscode\\code\\testwork\\testFile\\"
#头像图片路径
outputPath=r"C:E:\\vscode\\code\\testwork\\testFile\\output\\"
#处理后输出路径
fontPath=r"C:\\Windows\\Fonts\\"
#字体路径
headFile="head.jpg" #头像文件
outFile="output.jpg" #输出文件
#打开图片,建立画布
image=Image.open(headPath+headFile,'r')
draw=ImageDraw.Draw(image)
#由图片大小确定字体大小
fontsize=min(image.size)/4
#增加文字
fontobj=ImageFont.truetype(font=fontPath+"AdobeHeitiStd-Regular.otf",size=fontsize,index=0,encoding='',filename=None)#实例字体对象
draw.text((image.size[0]-fontsize,0),text="5",fill=(255,0,0),font=fontobj,anchor=None)#用draw对象的text()方法添加文字
image.save(outputPath+outFile)#保存图片
"""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2016/12/12 上午10:13
# @Author : hukezhu
# @Site :
# @File : 0000:添加未读消息.py
# @Software: PyCharm
from PIL import Image, ImageDraw, ImageFont
#创建图片对象
headImage = Image.open('E:/vscode/code/testwork/testFile/head.jpg')
#获取图片对象的宽高
w,h = headImage.size
#创建字体对象
font = ImageFont.truetype('C:/Windows/Fonts/Arial.ttf',int(h/4))
#绘制圆形
ImageDraw.Draw(headImage).pieslice([(w/3*2,0),(w,h/3)],0,360,fill='red')
ImageDraw.Draw(headImage).text((w*0.76,h*0.02),'3',font = font, fill = 'white')
#展示绘制结果(使用系统默认的图片浏览器)
#headImage.show()
#保存绘制结果
headImage.save('E:/vscode/code/testwork/testFile/wode.jpg')