Is there a way to compress the gif while making it with imageio
in python
? I am making gif with about 200 images and the final file is 30MB. I would prefer if it is 5-10 MB. Anyway the images are mono-colour so should be fine to compress. Is there a tool I can use or specify it with imageio
?
Here is my code to make gif :
import os
import imageio as io
import re
# Key to sort the file_names in order
numbers = re.compile(r'(\d+)')
def numericalSort(value):
parts = numbers.split(value)
parts[1::2] = map(int, parts[1::2])
return parts
file_names = sorted((fn for fn in os.listdir('.') if fn.startswith('timestamp_')), key = numericalSort)
# GIF writer
with io.get_writer('output_gif.gif', mode='I', duration=0.1) as writer:
for filename in file_names:
image = io.imread(filename)
writer.append_data(image)