-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathschdocpreview.py
31 lines (28 loc) · 883 Bytes
/
schdocpreview.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
from tkinter import Tk, PhotoImage, Label
from configparser import ConfigParser
from binascii import unhexlify
import zlib
from sys import stdin
from io import BytesIO
image = ConfigParser(interpolation=None)
image.read_file(stdin)
width = image.getint("Preview", "LargeImageWidth", raw=True)
height = image.getint("Preview", "LargeImageHeight", raw=True)
ppm = BytesIO()
ppm.write(
"P6\n"
"{} {}\n"
"255\n".format(width, height).encode("ascii")
)
image = image.get("Preview", "LargeImage", raw=True)
image = zlib.decompress(unhexlify(image))
for row in range(height):
for col in range(width):
pixel = ( (height - row) * width + col ) * 4
pixel = int.from_bytes(image[pixel:pixel + 4], "little")
ppm.write(pixel.to_bytes(3, "big"))
tk = Tk()
image = PhotoImage(data=ppm.getvalue())
label = Label(tk, image=image)
label.pack()
tk.mainloop()