PIL 读取字体 并输出图片

python 阅读:526
#coding:utf-8

import Image, ImageDraw, ImageFont

im = Image.new(mode='RGB',size=(400,100),color=(0,0,0))

draw = ImageDraw.Draw(im)

font = ImageFont.truetype(u'c:\\windows\\fonts\\方正特粗光辉简体.TTF',100)

outtext = '我是中文'

#draw.rectangle([(0,0),(100,100)], outline=(255,0,0), fill=(0,0,0))

#draw.rectangle([(200,0),(300,100)], outline=(255,0,0), fill=(0,0,0))

draw.text((0,0),outtext.decode('utf8'),fill=(255,0,0),font=font)

draw.line([(100,0),(100,100)],fill=(255,0,0))

draw.line([(200,0),(200,100)],fill=(255,0,0))

draw.line([(300,0),(300,100)],fill=(255,0,0))

im.show()

#im.save(outtext.decode('utf8')+'.jpg','JPEG')