2016-08-25 21:33:07 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
2016-09-02 00:29:26 +08:00
|
|
|
from PIL import Image
|
2016-08-30 20:43:52 +08:00
|
|
|
import os
|
2016-08-25 21:33:07 +08:00
|
|
|
|
2016-09-05 22:37:55 +08:00
|
|
|
def draw_qrcode(abspath, qrmatrix):
|
|
|
|
|
unit_len = 3
|
2016-08-30 20:43:52 +08:00
|
|
|
x = y = 4*unit_len
|
|
|
|
|
pic = Image.new('1', [(len(qrmatrix)+8)*unit_len]*2, 'white')
|
2016-08-25 21:33:07 +08:00
|
|
|
|
2016-08-30 20:43:52 +08:00
|
|
|
for line in qrmatrix:
|
|
|
|
|
for module in line:
|
|
|
|
|
if module:
|
2016-09-02 00:29:26 +08:00
|
|
|
draw_a_black_unit(pic, x, y, unit_len)
|
2016-08-25 21:33:07 +08:00
|
|
|
x += unit_len
|
2016-08-30 20:43:52 +08:00
|
|
|
x, y = 4*unit_len, y+unit_len
|
2016-08-25 21:33:07 +08:00
|
|
|
|
2016-09-05 12:59:30 +08:00
|
|
|
saving = os.path.join(abspath, 'qrcode.png')
|
2016-08-30 20:43:52 +08:00
|
|
|
pic.save(saving)
|
2016-09-02 00:29:26 +08:00
|
|
|
return saving
|
|
|
|
|
|
|
|
|
|
def draw_a_black_unit(p, x, y, ul):
|
|
|
|
|
for i in range(ul):
|
|
|
|
|
for j in range(ul):
|
|
|
|
|
p.putpixel((x+i, y+j), 0)
|