1
0
mirror of https://github.com/x-hw/amazing-qr.git synced 2025-12-05 23:08:16 +02:00
Files
amazing-qr/draw.py

22 lines
562 B
Python
Raw Normal View History

2016-08-25 21:33:07 +08:00
# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw
2016-08-30 20:43:52 +08:00
import os
2016-08-25 21:33:07 +08:00
2016-08-30 20:43:52 +08:00
def draw_qrcode(abspath, qrmatrix):
2016-08-25 21:33:07 +08:00
unit_len = 9
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
draw = ImageDraw.Draw(pic)
2016-08-30 20:43:52 +08:00
for line in qrmatrix:
for module in line:
if module:
2016-08-25 21:33:07 +08:00
draw.rectangle([x,y,x+unit_len,y+unit_len], fill = 0)
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)
#pic.show()
return saving