Mac Terminal - Create animated gif from png files
Asked Answered
S

2

31

I have a bunch of png files named as 1.png, 2.png, etc. and I want to create an animated gif image from them all. I haven't been successful in finding a solution for a terminal command that will convert these png files into a single animated gif.

Can someone post some commands that I can try? I have tried "convert" commands but my terminal always says convert is not found even though I have installed ImageMagik.

Silken answered 21/11, 2013 at 16:40 Comment(1)
If you are (fairly) sure convert should be somewhere in your system, try whereis.Levitation
S
54

convert *.png screens.gif

This answer suggested installing convert with brew install ImageMagick.

Spence answered 26/4, 2014 at 10:5 Comment(3)
You can run this from the Finder context menu with Automator: jacobsalmela.com/2015/11/02/…Astronaut
This won't take the ordering of your frames.Smolder
Thanks a lot!!, I did not know I could convert files so easySupervisor
M
37

ImageMagick's convert command works perfectly for this but you'll want to list the filenames in the correct order. Using *.png will jumble frames if the digits don't have the leading zeros because the ordering is alphabetical:

1.png  10.png  11.png  2.png  3.png  ...

If you use zsh you can simply use a glob qualifier:

convert *.png(n) out.gif

Otherwise you can sort the ls output

convert $(ls *.png | sort -V) out.gif

If your filenames have leading zeros go ahead and use *.png. Note that the default delay between frames is small, so depending on your use case the frame rate might be too quick. To change that use the -delay option, for example:

convert -delay 50 *.png out.gif

This will set FPS to 100/50 = 2 frames per second.

Mollee answered 21/12, 2020 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.