|
import os |
|
from PIL import Image |
|
import argparse |
|
|
|
parser = argparse.ArgumentParser(description='change to useful name') |
|
parser.add_argument('--dim', default=128, type=int, help='dimention image') |
|
args = parser.parse_args() |
|
|
|
path = "." |
|
dirs = os.listdir(path) |
|
|
|
dim = args.dim |
|
|
|
def gif_order (data, center=True): |
|
gif = [] |
|
base = 1 |
|
|
|
|
|
i = int((len(data)-2)/2) |
|
while(i > base ): |
|
gif.append(data[i]) |
|
|
|
i -= 1 |
|
|
|
|
|
|
|
gif.append(data[int((len(data)-2)/2) + 1]) |
|
|
|
|
|
|
|
if center: |
|
gif.append(data[0]) |
|
|
|
|
|
|
|
gif.append(data[int((len(data) - 2) / 2) + 2]) |
|
|
|
|
|
i = int((len(data)-2)/2) + 3 |
|
while (i < len(data)): |
|
gif.append(data[i]) |
|
|
|
i += 1 |
|
|
|
|
|
invertedgif = gif[::-1] |
|
invertedgif = invertedgif[1:] |
|
|
|
gif = gif[1:] + invertedgif |
|
|
|
|
|
|
|
|
|
return gif |
|
|
|
|
|
|
|
for file in dirs: |
|
if ".jpg" in file or ".png" in file: |
|
rowImages = [] |
|
im = Image.open("./" + file) |
|
width, height = im.size |
|
im = im.convert('RGB') |
|
|
|
|
|
|
|
pointleft = 3 |
|
pointtop = 3 |
|
i = 0 |
|
while (pointtop < height): |
|
while (pointleft < width): |
|
im1 = im.crop((pointleft, pointtop, dim+pointleft, dim+pointtop)) |
|
rowImages.append(im1.quantize()) |
|
|
|
pointleft+= dim+4 |
|
|
|
rowImages = gif_order(rowImages,center=False) |
|
name = file[:-4] + "_" + str(i) + '.gif' |
|
rowImages[0].save(name, save_all=True,format='GIF', append_images=rowImages[1:], optimize=True, duration=100, loop=0) |
|
pointtop += dim + 4 |
|
pointleft = 3 |
|
rowImages = [] |
|
i+=1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|