31 lines
701 B
Python
Executable File
31 lines
701 B
Python
Executable File
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
from PIL import Image
|
|
|
|
from amzqr.mylibs.constant import PIXELS_PER_MODULE
|
|
|
|
|
|
def draw_qrcode(abspath, qrmatrix):
|
|
unit_len = PIXELS_PER_MODULE
|
|
x = y = 4 * unit_len
|
|
pic = Image.new("1", [(len(qrmatrix) + 8) * unit_len] * 2, "white")
|
|
|
|
for line in qrmatrix:
|
|
for module in line:
|
|
if module:
|
|
draw_a_black_unit(pic, x, y, unit_len)
|
|
x += unit_len
|
|
x, y = 4 * unit_len, y + unit_len
|
|
|
|
saving = os.path.join(abspath, "qrcode.png")
|
|
pic.save(saving)
|
|
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)
|