Skip to content

Commit

Permalink
在非windows系统u'\u2588'只占一个英文字符宽度,导致命令行二维码显示错位
Browse files Browse the repository at this point in the history
  • Loading branch information
tempdban authored and littlecodersh committed Jul 24, 2016
1 parent 9dbfcd3 commit c1a52e2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ itchat.egg-info/*
*.swp
test.py
itchat.pkl
QR.jpg
2 changes: 1 addition & 1 deletion itchat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_QR(self, uuid = None, enableCmdQR = False):
QR_DIR = 'QR.jpg'
with open(QR_DIR, 'wb') as f: f.write(r.content)
if enableCmdQR:
tools.print_cmd_qr(QR_DIR)
tools.print_cmd_qr(QR_DIR, enableCmdQR = enableCmdQR)
else:
tools.print_qr(QR_DIR)
return True
Expand Down
9 changes: 8 additions & 1 deletion itchat/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ def print_qr(fileDir):
try:
from PIL import Image
def print_cmd_qr(fileDir, size = 37, padding = 3,
white = BLOCK, black = ' '):
white = BLOCK, black = ' ', enableCmdQR = True):
img = Image.open(fileDir)
times = img.size[0] / (size + padding * 2)
rgb = img.convert('RGB')
try:
blockCount = int(enableCmdQR)
assert(0 < blockCount)
except:
blockCount = 1
finally:
white *= blockCount
sys.stdout.write(' '*50 + '\r')
sys.stdout.flush()
qr = white * (size + 2) + '\n'
Expand Down

0 comments on commit c1a52e2

Please sign in to comment.