python qrcode生成彩色二维码

安装qrcode参见:https://github.com/lincolnloop/python-qrcode

def demo():
	img = qrcode.make("你今年要发财啊!!!")
	# 改变颜色
	img = img.convert("RGBA")
	datas = img.getdata()
	newData = []
	for item in datas:
		if item[0] == 0 and item[1] == 0 and item[2] == 0:
			newData.append((8,99,190,0)) 
		else:
			newData.append(item)
	img.putdata(newData)
	# 改变颜色结束
	imgFile = StringIO.StringIO()
	img.save(imgFile,'jpeg');
	return Response(imgFile.getvalue(),mimetype='image/jpeg')


你可能感兴趣的:(python,二维码,qrcode)