-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathcreate_gif.py
39 lines (27 loc) · 955 Bytes
/
create_gif.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
'''Script to convert multiple images into a gif. Found out about imageio here:
http://stackoverflow.com/questions/753190/programmatically-generate-video-or-animated-gif-in-python'''
import glob
import sys
import imageio
DURATION = 1.5
OUT_GIF = 'out.gif'
VALID_EXTENSIONS = ('png', 'jpg')
def create_gif(filenames, duration=DURATION):
images = []
for filename in filenames:
images.append(imageio.imread(filename))
imageio.mimsave(OUT_GIF, images, duration=duration)
if __name__ == "__main__":
script = sys.argv.pop(0)
args = sys.argv
if len(args) == 0:
print('Usage: {} <glob pattern or list images>'.format(script))
sys.exit(1)
elif len(args) == 1:
filenames = glob.glob(args[0])
else:
filenames = args
if not all(f.lower().endswith(VALID_EXTENSIONS) for f in filenames):
print('Only png and jpg files allowed')
sys.exit(1)
create_gif(filenames)