Skip to content

Instantly share code, notes, and snippets.

@jc4p
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc4p/cac925f58e9926ec763e to your computer and use it in GitHub Desktop.
Save jc4p/cac925f58e9926ec763e to your computer and use it in GitHub Desktop.
Turns a SE holiday party photo booth pic into a GIF
from PIL import Image
from moviepy.editor import ImageSequenceClip
from os import remove
import sys
# The width and height for each picture in the x2-size image.
pic_size = 485, 368
def get_frame(img, x, y):
return img.crop((x, y, x + pic_size[0], y + pic_size[1]))
def make_gif(filename):
im = Image.open(filename)
image_names = ["frame_{}.jpg".format(x) for x in range(4)]
newName = filename[:filename.find(".")] + ".gif"
get_frame(im, 29, 29).save(image_names[0], quality=100)
get_frame(im, 549, 29).save(image_names[1], quality=100)
get_frame(im, 29, 432).save(image_names[2], quality=100)
get_frame(im, 549, 432).save(image_names[3], quality=100)
clip = ImageSequenceClip(image_names, fps=4)
clip.write_gif(newName, fuzz=False)
for f in image_names:
remove(f)
print ""
if __name__ == "__main__":
make_gif(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment