Tomas Vik

How to create animated gif from multiple images with ImageMagick

Read this tutorial if you have several images and you would like to make them into an animated gif.

This quick tutorial is going to work best for you if you are on Mac OS and you know how to run commands in the terminal. Every Unix system should work fine; you’ll just need to install the dependencies differently.

Note: This article is much more technical than what I usually write, let me know if you likeπŸ‘ or dislikeπŸ‘Ž it.

Install prerequisites and get your images ready

This section uses Mac OS homebrew package manager, but you can find the dependencies on any Unix system.

  1. Install ImageMagick with brew install imagemagick.
  2. Install Gimp with brew cask install gimp.
    • Skip installing Gimp if you don’t need to custom crop your images.

Now put your images in one folder. Alphabetical order of the file names will decide the order in which the pictures show in the animation.

└── folder-for-images
    β”œβ”€β”€ 2020-07-07.jpg
    β”œβ”€β”€ 2020-07-08.jpg
    β”œβ”€β”€ 2020-07-09.jpg
 Β Β  └── 2020-07-10.jpg

If you need more complex renaming and you are not a shell scripting guru, have a look at massren. It lets you use your favourite editor to rename multiple files.

Let’s move to the gif making.

Step 0: Custom crop your images (optional)

This step is optional and is only necessary if your images contain the subject of animation in different spots, For example, if you were taking screenshots, and each image has a different aspect ratio.

This step takes the largest portion of the time, so try to avoid it at the time you are getting the pictures.

Goal: Make sure that all the images contain the same object at the same spot.

first second
before core-small0.png core-small1.png
after cropped-core0.png cropped-core1.png
  1. Drag all the images into Gimp window
  2. Select the crop tool crop tool
  3. Zoom in zoom
  4. Crop each image and export it. (File -> Export as)

Step 1: Use ImageMagick to create the gif

Now we run one command that will do all the work. The command is not changing the current images so you don’t have to worry about losing your data.

cd folder-for-images
convert \
  2020*.jpg \
  -gravity center -crop 1:1 +repage \
  -resize 800x800 \
  -set delay 50 \

Explaining the command

The convert command is part of the ImageMagick installation.

graph TD;
A["Gather image files"] --> B
B["Corp images to aspect ratio (optional)"] --> C
C["Resize images (optional)"] --> D
D["Set animation delay"]


Gif from photos

Animated cactus

Gif from screenshots

This one is from my previous article: How my article became one-hit-wonder on hacker news.

HN front page