Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WIDTH1 = 144 # width scale
- HEIGHT1 = 72 # height scale
- import os
- import time
- import pyautogui
- from colormap import rgb2hex
- from PIL import Image
- from shutil import move
- import re
- mode = 2
- x = 0
- def tobyte(r,g,b):
- a = chr(r)+chr(g)+chr(b)
- return a
- while True:
- time.sleep(1/10)
- #
- im = pyautogui.screenshot()
- new_im = im.resize((WIDTH1, HEIGHT1),Image.ANTIALIAS)
- #
- npd = ''
- for pixel in new_im.getdata():
- r,g,b = pixel
- if mode == 2: #hex compression
- npd = npd + rgb2hex(r,g,b)
- elif mode == 3: #byte compression
- npd = npd + tobyte(r,g,b)
- else: #grayscale compression
- npd = npd + str("{:03d}".format(r+g+b))
- if mode == 3:
- npd = npd.encode('utf8')
- pixf = open("data_r.json", "wb+")
- elif mode == 2:
- npd = npd.replace('#', '', len(npd))
- pixf = open("data_r.json", "w+")
- else:
- pixf = open("data_r.json", "w+")
- sizef = open("size_r.json", "w+")
- st = [WIDTH1, HEIGHT1]
- fst = re.sub('[ ]', '', str(st))
- pixf.write(npd)
- sizef.write(fst)
- pixf.close()
- sizef.close()
- f = 'data_r.json'
- move(f,f.replace('_r.json','.json'))
- f2 = 'size_r.json'
- move(f2,f2.replace('_r.json','.json'))
- #
- x += 1
- print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement