提交 b7ffd3e6 编写于 作者: L LittleCoder

Use better look cmd QRCode [PR#36: tempdban]

上级 b2561646
from PIL import Image
import sys, os, platform
import sys, os
BLOCK = '\xA1\xF6' if platform.system() == 'Windows' else 'MM'
QR_DIR = '.'
try:
b = u'\u2588'.encode(sys.stdin.encoding)
sys.stdout.write(b + '\r')
sys.stdout.flush()
except:
BLOCK = 'MM'
else:
BLOCK = b
class QRCode():
def __init__(self, fileName, size, padding = 0, background = 'BLACK'):
......@@ -15,16 +23,17 @@ class QRCode():
def print_qr(self):
sys.stdout.write(' '*50 + '\r')
sys.stdout.flush()
print self.white * (self.size + 2)
print(self.white * (self.size + 2))
startPoint = self.padding + 0.5
for y in range(self.size):
sys.stdout.write(self.white)
for x in range(self.size):
r,g,b = self.rgb.getpixel(((x + startPoint) * self.times, (y + startPoint) * self.times))
sys.stdout.write(self.white if r > 127 else self.black)
print self.white
print self.white * (self.size + 2)
print(self.white)
print(self.white * (self.size + 2))
if __name__ == '__main__':
# 37 is for picture size without padding, 3 is padding
q = QRCode(os.path.join(os.path.pardir, 'log', 'QR.jpg'), 37, 3, 'BLACK')
q.print_qr()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册