import os from PIL import Image import argparse import imageio import numpy as np import cv2 import mediapy as media parser = argparse.ArgumentParser(description='change to useful name') parser.add_argument('--dim', default=256, type=int, help='dimention image') args = parser.parse_args() path = "." ROOT_DIR = os.path.dirname(__file__) dirs = os.listdir(ROOT_DIR) dim = args.dim def createVideo(array_pil, space_time = 5, name = "out_"): ar_im = [] for j in range(3): for image in array_pil: for i in range (0,space_time): ar_im.append(np.array(image)) media.write_video(name +".mp4" , ar_im, fps=30, qp=18) def gif_order (data, center=True): gif = [] base = 1 #primera mitad i = int((len(data)-2)/2) while(i > base ): gif.append(data[i]) #print(i) i -= 1 #el del medio izq gif.append(data[int((len(data)-2)/2) + 1]) #print(int((len(data)-2)/2) + 1) #el inicial if center: gif.append(data[0]) #print(0) # el del medio der gif.append(data[int((len(data) - 2) / 2) + 2]) #print(int((len(data) - 2) / 2) +2) #segunda mitad i = int((len(data)-2)/2) + 3 while (i < len(data)): gif.append(data[i]) #print(i) i += 1 #print("---------") invertedgif = gif[::-1] invertedgif = invertedgif[1:] gif = gif[1:] + invertedgif #print(gif) #for image in gif: # image.show() #gsdfgsfgf return gif print(" [*] Init gif generations!") # This would print all the files and directories for file in dirs: if ".jpg" in file or ".png" in file: rowImages = [] im = Image.open("./" + ROOT_DIR + '/' + file) width, height = im.size #im = im.convert('P') #CROP (left, top, right, bottom) pointleft = 3 pointtop = 3 i = 0 while (pointtop < height): while (pointleft < width): im1 = im.crop((pointleft, pointtop, dim+pointleft, dim+pointtop)) #h1 = im1.size[0] * 4 #im1 = im1.resize([h1,h1], Image.Resampling.LANCZOS) rowImages.append(im1) #im1.show() pointleft+= dim+4 # Ya tengo todas las imagenes podria hacer el gif aca rowImages = gif_order(rowImages,center=False) createVideo(rowImages, 3, name = "./" + ROOT_DIR + '/' + file[:-4] + "_" + str(i)) name = "./" + ROOT_DIR + '/' + file[:-4] + "_" + str(i) + '.gif' rowImages[0].save(name, save_all=True,format='GIF', append_images=rowImages[1:], optimize=True, duration=100, loop=0) #print(rowImages) pointtop += dim + 4 pointleft = 3 rowImages = [] i+=1 #im2 = im.crop((width / 2, 0, width, height)) # im2.show() #im1.save("./2" + file[:-4] + ".png") #im2.save("./" + file[:-4] + ".png") # Deleted #os.remove("data/" + file) print(" [*] End gif generations!")