1
0
mirror of https://github.com/x-hw/amazing-qr.git synced 2025-12-03 22:59:09 +02:00
Files
amazing-qr/mylibs/draw.py

24 lines
613 B
Python
Raw Normal View History

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-02 00:29:26 +08:00
def draw_qrcode(abspath, qrmatrix, unit_len):
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-08-30 20:43:52 +08:00
saving = os.path.join(abspath, 'qrcode.jpg')
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)