-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqr.py
40 lines (30 loc) · 1.03 KB
/
qr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import subprocess
import pyqrcode
import os
SCALE = 6
OUT_FILE = r"qr.png"
def windows_photo_viewer(filename):
RUNDLL32_FILENAME = os.path.join(os.environ["SYSTEMROOT"], "System32", "rundll32.exe")
PHOTOVIEWER_FILENAME = os.path.join(os.environ["PROGRAMFILES"], "Windows Photo Viewer", "PhotoViewer.dll")
WINDOWS_PHOTO_VIEWER_PATH = [RUNDLL32_FILENAME, PHOTOVIEWER_FILENAME, "ImageView_Fullscreen"]
subprocess.call(WINDOWS_PHOTO_VIEWER_PATH + [filename])
def render_qr(filename, text=None):
code = pyqrcode.create(text)
with open(filename, "wb") as fstream:
code.png(fstream, scale=SCALE)
def display_picture(filename):
try:
# for most cases
windows_photo_viewer(filename)
except:
# just incase we support nix in the future or something
import PIL.Image
image = PIL.Image.open(filename)
image.show()
def main():
text = sys.stdin.read()
render_qr(OUT_FILE, text=text)
display_picture(OUT_FILE)
if __name__ == "__main__":
main()