/
gif-maker.py
67 lines (47 loc) · 1.66 KB
/
gif-maker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
import glob
from PIL import Image
import argparse
import textwrap
import sys
from collections import defaultdict
parser = argparse.ArgumentParser(
prog="gif-maker.py",
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''
************************************************************************
Developed by Arkadiy Garber
Please send comments and inquiries to ark@midauthobio.edu
************************************************************************
'''))
parser.add_argument('-d', type=str, help="directory with images", default="NA")
parser.add_argument('-o', type=str, help="output gif", default="NA")
parser.add_argument('-x', type=str, help="filename extension", default="png")
parser.add_argument('-s', type=int, help="frame speed", default=100)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(0)
args = parser.parse_known_args()[0]
def lastItem(ls):
x = ''
for i in ls:
if i != "":
x = i
return x
# key=lambda i: ((i.split(".")[0]), float(lastItem(i.split(".")[0].split("/"))) )
Dict = defaultdict(lambda: 'EMPTY')
for i in glob.glob(args.d + "/*" + args.x):
POS = lastItem(i.split("/"))
POS = POS.split(".")[0]
Dict[int(POS)] = i
sortedList = []
for i in sorted(Dict.keys()):
sortedList.append(Dict[i])
def make_gif(frame_folder):
frames = [Image.open(image) for image in sortedList]
# frames.reverse()
frame_one = frames[0]
frame_one.save(args.o, format="GIF", append_images=frames,
save_all=True, duration=args.s, loop=0)
if __name__ == "__main__":
make_gif(args.d)