TIL: Batch resize images and create animated gifs from command line

Today I needed to combine some of my pictures from my mobile to an animated gif. Since using GUI tools is no option of course, here is how to do it from the command line.
First of all, make sure you have ImageMagick installed on your system.

Once installed you are ready to go.
Assuming we have the following file structure and want all JPEG files to be resized.

1
2
3
4
5
6
.
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
└── output

To make them, let’s say 25% smaller, you can run the following command:

1
mogrify -resize 25% *.jpg

You could also run something like:

1
mogrify -resize 1600x1200 *.jpg

Note that mogrify will replace your original files with the resized ones, so consider backing up your originals before running this.

After resizing, now create the gif using

1
convert -delay 35 -loop 0 *.jpg output/animated.gif

and your done, your gif will be placed in the output folder.