KrYn0MoRe

ex3

Oct 27th, 2020
1,180
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WIDTH1 = 0
  2. HEIGHT1 = 0
  3. import re
  4. import os
  5. import time
  6. from colormap import rgb2hex
  7. from PIL import Image
  8. from shutil import move
  9.  
  10. mode = 2
  11.  
  12. def tobyte(r,g,b):
  13.     a = chr(r)+chr(g)+chr(b)
  14.     return a
  15.  
  16. FILEINPUT = input("Input gif file. ")
  17. if not FILEINPUT or not os.path.exists(FILEINPUT):
  18.     print("Invalid gif file.")
  19. else:
  20.     #
  21.     im = Image.open(FILEINPUT)
  22.     width, height = im.size
  23.     div = float(input("Input multiplier size. "))
  24.     WIDTH1 = round(width*div)
  25.     HEIGHT1 = round(height*div)
  26.     bruh = True
  27.     c1 = input("Gif will be " + str(HEIGHT1) + "x" + str(WIDTH1) + " resolution. Continue? (y/n)")
  28.     if str.lower(c1) == 'y':
  29.         print("Running..")
  30.         pass
  31.     else:
  32.         print("Quitting..")
  33.         bruh = False
  34.     #
  35.     while bruh:
  36.         time.sleep(1/10)
  37.         for fr in range(0,im.n_frames):
  38.             #
  39.             time.sleep(1/10)
  40.             im.seek(fr)
  41.             new_im = im.resize((WIDTH1, HEIGHT1),Image.ANTIALIAS)
  42.             new_im = new_im.convert("RGB")
  43.             npd = ''
  44.             for pixel in new_im.getdata():
  45.                 r,g,b = pixel
  46.                 if mode == 2: #hex compression
  47.                     npd = npd + rgb2hex(r,g,b)
  48.                 elif mode == 3: #byte compression
  49.                     npd = npd + tobyte(r,g,b)
  50.                 else: #grayscale compression
  51.                     npd = npd + str("{:03d}".format(r+g+b))
  52.             if mode == 3:
  53.                 npd = npd.encode('utf8')
  54.                 pixf = open("data_r.json", "wb+")
  55.             elif mode == 2:
  56.                 npd = npd.replace('#', '', len(npd))
  57.                 pixf = open("data_r.json", "w+")
  58.             else:
  59.                 pixf = open("data_r.json", "w+")
  60.             sizef = open("size_r.json", "w+")
  61.             st = [WIDTH1, HEIGHT1]
  62.             fst = re.sub('[ ]', '', str(st))
  63.             pixf.write(npd)
  64.             sizef.write(fst)
  65.             pixf.close()
  66.             sizef.close()
  67.             f = 'data_r.json'
  68.             move(f,f.replace('_r.json','.json'))
  69.             f2 = 'size_r.json'
  70.             move(f2,f2.replace('_r.json','.json'))
  71.             #
  72.             print("Success frame: " + str(fr))
  73.  
RAW Paste Data