Image for post
Image for post

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, Ph.D.
Jan 23 · 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

Medium's largest active publication, followed by +720K people. Follow to join our community.

Yong Cui, Ph.D.

Written by

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

Medium's largest active publication, followed by +720K people. Follow to join our community.

Yong Cui, Ph.D.

Written by

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

Medium's largest active publication, followed by +720K people. Follow to join our community.

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store