Create Animated Images Using Python

No Photoshop? Not a problem! Learn how to easily create animated images from a list of static images or a video in Python.

Yong Cui
Yong Cui
Jan 23, 2020 · 7 min read

Introduction

Overview

pip install imageio
pip install imageio-ffmpeg
pip install pygifsicle

Creation of Animated Images

From Individual Images

from pathlib import Pathimage_path = Path('source_images')
images = list(image_path.glob('*.png'))
image_list = []
for file_name in images:
image_list.append(imageio.imread(file_name))
imageio.mimwrite('animated_from_images.gif', image_list)

From a Video

video_read = imageio.mimread('video_to_gif.mov')
imageio.mimwrite('animated_from_video.gif', video_read)

Optimization of Animated Images

Review of the Current Status

Specify How the Animated Images Are Created

Reduce File Size

from pygifsicle import optimizegif_path = 'animated_from_video.gif'# create a new one
optimize(gif_path, 'animated_from_video_optimized.gif')
# overwrite the original one
optimize(gif_path)

Conclusions

The Startup

Get smarter at building your thing. Join The Startup’s +792K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Yong Cui

Written by

Yong Cui

Work at the nexus of biomedicine, data science & mobile dev. Love to write on these technological topics. Follow me @ycui01 on Twitter to get latest articles.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +792K followers.

Yong Cui

Written by

Yong Cui

Work at the nexus of biomedicine, data science & mobile dev. Love to write on these technological topics. Follow me @ycui01 on Twitter to get latest articles.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +792K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium