Skip to content

Instantly share code, notes, and snippets.

@m8ttyB
Last active April 10, 2017 20:40
Show Gist options
  • Save m8ttyB/5022ab61dac8f568e10bcda32872e47d to your computer and use it in GitHub Desktop.
Save m8ttyB/5022ab61dac8f568e10bcda32872e47d to your computer and use it in GitHub Desktop.
Generate a gif from your jpgs
#!/usr/bin/env python
from lib import picture as p
import sys
if __name__ == '__main__':
jpg_filenames = p.list_images(sys.argv[1])
p.build_gif(jpg_filenames)
import imageio
from glob import iglob
import os
from PIL import Image
class Picture:
def __init__(self, filename):
self.filename = filename
self.thumbnail = self.create_thumbnail()
def create_thumbnail(self):
file, ext = os.path.splitext(self.filename)
thumbnail = file + '.thumbnail'
size = (350, 350)
img = Image.open(self.filename)
img.thumbnail(size, Image.ANTIALIAS)
img.save(thumbnail, "JPEG")
return thumbnail
def delete_thumbnail(self):
os.remove(self.thumbnail)
def build_gif(filenames):
images = []
pictures = []
for filename in filenames:
pic = Picture(filename)
pictures.append(pic)
images.append(imageio.imread(pic.thumbnail))
imageio.mimsave('movie.gif', images)
# remove temporary thumbnail images
for pic in pictures:
pic.delete_thumbnail()
def list_images(path, ext='*.JPG'):
files = []
path = path + ext
for file in iglob(path):
files.append(file)
return files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment