python-PIL显示中文

本文介绍了如何在Python的PIL库中正确显示中文字符,首先需要确保安装了PIL模块。
摘要由CSDN通过智能技术生成
# coding=gbk

import Image, ImageDraw, ImageFont

def drawSomething (fname, drawType, outpic):
	img = Image.open(fname)
	draw = ImageDraw.Draw(img)
	width, height = img.size
	
	if drawType == "crossline":
		draw.line(((0, 0), (width-1, height-1)), fill=255)
		draw.line(((0, height-1), (width-1, 0)), fill=255)
		print "draw line"
	elif drawType == "arc":
		draw.arc((0, 0, width-1, height-1), 180, 270, fill=255)
		print "draw arc"

	img.save(outpic)

def drawFont (txt):
	font = ImageFont.truetype("C:\\WINDOWS\\Fonts\\SIMYOU.TTF", 40)
	img = Image.new("RGB", (400, 300))
	draw = ImageDraw.Draw(img)
	draw.ink = 0 + 255*256 + 0*255*256
	#draw.text((20, 120), unicode(txt, 'gbk'), font=font)
	draw.text((20, 120), txt, font=font)
	img.save("text.jpg")


if __name__ == '__main__':
#	img.show()
#	newimg =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值