Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WIDTH1 = 0
- HEIGHT1 = 0
- import re
- import os
- import time
- from colormap import rgb2hex
- from PIL import Image
- from shutil import move
- mode = 2
- def tobyte(r,g,b):
- a = chr(r)+chr(g)+chr(b)
- return a
- FILEINPUT = input("Input gif file. ")
- if not FILEINPUT or not os.path.exists(FILEINPUT):
- print("Invalid gif file.")
- else:
- #
- im = Image.open(FILEINPUT)
- width, height = im.size
- div = float(input("Input multiplier size. "))
- WIDTH1 = round(width*div)
- HEIGHT1 = round(height*div)
- bruh = True
- c1 = input("Gif will be " + str(HEIGHT1) + "x" + str(WIDTH1) + " resolution. Continue? (y/n)")
- if str.lower(c1) == 'y':
- print("Running..")
- pass
- else:
- print("Quitting..")
- bruh = False
- #
- while bruh:
- time.sleep(1/10)
- for fr in range(0,im.n_frames):
- #
- time.sleep(1/10)
- im.seek(fr)
- new_im = im.resize((WIDTH1, HEIGHT1),Image.ANTIALIAS)
- new_im = new_im.convert("RGB")
- 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'))
- #
- print("Success frame: " + str(fr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement