2016-08-25 21:33:07 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
|
2016-08-27 11:27:09 +08:00
|
|
|
# test:
|
2016-08-25 21:33:07 +08:00
|
|
|
m1 = [[1]*7+[0]*7+[1]*7,
|
|
|
|
[1,0,0,0,0,0,1]+[0]*7+[1,0,0,0,0,0,1],
|
|
|
|
[1,0,1,1,1,0,1]+[0]*7+[1,0,1,1,1,0,1],
|
|
|
|
[1,0,1,1,1,0,1]+[0]*7+[1,0,1,1,1,0,1],
|
|
|
|
[1,0,1,1,1,0,1]+[0]*7+[1,0,1,1,1,0,1],
|
|
|
|
[1,0,0,0,0,0,1]+[0]*7+[1,0,0,0,0,0,1],
|
|
|
|
[1]*7+[0,1,0,1,0,1,0]+[1]*7,
|
|
|
|
[0]*21,
|
|
|
|
[0]*6+[1]+[0]*14,
|
|
|
|
[0]*21,
|
|
|
|
[0]*6+[1]+[0]*14,
|
|
|
|
[0]*21,
|
|
|
|
[0]*6+[1]+[0]*14,
|
|
|
|
[0]*21,
|
|
|
|
[1]*7+[0]*14,
|
|
|
|
[1,0,0,0,0,0,1]+[0]*14,
|
|
|
|
[1,0,1,1,1,0,1]+[0]*14,
|
|
|
|
[1,0,1,1,1,0,1]+[0]*14,
|
|
|
|
[1,0,1,1,1,0,1]+[0]*14,
|
|
|
|
[1,0,0,0,0,0,1]+[0]*14,
|
|
|
|
[1]*7+[0]*14
|
|
|
|
]
|
|
|
|
|
|
|
|
def draw_qrcode(qrmatrix):
|
|
|
|
x, y = 0, 0
|
|
|
|
unit_len = 9
|
|
|
|
pic = Image.new('1', [len(qrmatrix)*unit_len]*2, 'white')
|
|
|
|
draw = ImageDraw.Draw(pic)
|
|
|
|
|
|
|
|
for a in range(len(qrmatrix)):
|
|
|
|
for b in range(len(qrmatrix[a])):
|
|
|
|
if qrmatrix[a][b]:
|
|
|
|
draw.rectangle([x,y,x+unit_len,y+unit_len], fill = 0)
|
|
|
|
x += unit_len
|
|
|
|
x, y = 0, y+unit_len
|
|
|
|
|
|
|
|
pic.save('qrcode.jpg')
|
|
|
|
pic.show()
|
|
|
|
|
2016-08-27 11:27:09 +08:00
|
|
|
# test:
|
2016-08-27 16:29:56 +08:00
|
|
|
#draw_qrcode(m1)
|