Last active
April 10, 2017 20:40
-
-
Save m8ttyB/5022ab61dac8f568e10bcda32872e47d to your computer and use it in GitHub Desktop.
Generate a gif from your jpgs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imageio==2.1.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment