Advertisement
KrYn0MoRe

ex1

Oct 27th, 2020
2,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. WIDTH1 = 144 # width scale
  2. HEIGHT1 = 72 # height scale
  3. import os
  4. import time
  5. import pyautogui
  6. from colormap import rgb2hex
  7. from PIL import Image
  8. from shutil import move
  9. import re
  10.  
  11. mode = 2
  12. x = 0
  13.  
  14. def tobyte(r,g,b):
  15.     a = chr(r)+chr(g)+chr(b)
  16.     return a
  17.  
  18. while True:
  19.     time.sleep(1/10)
  20.     #
  21.     im = pyautogui.screenshot()
  22.     new_im = im.resize((WIDTH1, HEIGHT1),Image.ANTIALIAS)
  23.     #
  24.     npd = ''
  25.     for pixel in new_im.getdata():
  26.         r,g,b = pixel
  27.         if mode == 2: #hex compression
  28.             npd = npd + rgb2hex(r,g,b)
  29.         elif mode == 3: #byte compression
  30.             npd = npd + tobyte(r,g,b)
  31.         else: #grayscale compression
  32.             npd = npd + str("{:03d}".format(r+g+b))
  33.     if mode == 3:
  34.         npd = npd.encode('utf8')
  35.         pixf = open("data_r.json", "wb+")
  36.     elif mode == 2:
  37.         npd = npd.replace('#', '', len(npd))
  38.         pixf = open("data_r.json", "w+")
  39.     else:
  40.         pixf = open("data_r.json", "w+")
  41.     sizef = open("size_r.json", "w+")
  42.     st = [WIDTH1, HEIGHT1]
  43.     fst = re.sub('[ ]', '', str(st))
  44.     pixf.write(npd)
  45.     sizef.write(fst)
  46.     pixf.close()
  47.     sizef.close()
  48.     f = 'data_r.json'
  49.     move(f,f.replace('_r.json','.json'))
  50.     f2 = 'size_r.json'
  51.     move(f2,f2.replace('_r.json','.json'))
  52.     #
  53.     x += 1
  54.     print(x)
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement