8.20 BUUCTF python将GIF分解
调了半天创建实例后没有调用成员函数。。。
from PIL import Image
import os
import random
class GIF:
def __init__(self, file_name):
self.file_name = file_name
self.dir_name = self.file_name[:-4]
self.gif_name = os.path.join(os.path.dirname(__file__), file_name)
print(self.file_name,self.dir_name,self.gif_name,sep=' ----- ')
self.make_dir()
def make_dir(self):
try:
os.mkdir(self.dir_name)
except FileExistsError:
rdm = random.randint(1,10)
self.dir_name += str(rdm)
os.mkdir(self.dir_name)
def Divide(self):
img = Image.open(r'.gif')
cnt = 0
try:
while True:
now = img.tell()
cnt = cnt + 1
_pth = os.path.join(self.dir_name,f'{cnt}.png')
img.save(_pth)
img.seek(now + 1)
except Exception as e:
pass
if __name__ == '__main__':
GIF(r'.gif').Divide()