ImageMagick bash command - animated GIF <=> JPG/PNG
Accidentally or intentionally converted animated GIF to a bunch of JPGs or PNGs, by:
$ convert anime.gif anime.jpg
# above command output a bunch of files:
anime-0.jpg anime-12.jpg anime-16.jpg anime-2.jpg anime-23.jpg anime-5.jpg anime-9.jpg
anime-1.jpg anime-13.jpg anime-17.jpg anime-20.jpg anime-24.jpg anime-6.jpg anime.gif
anime-10.jpg anime-14.jpg anime-18.jpg anime-21.jpg anime-3.jpg anime-7.jpg
anime-11.jpg anime-15.jpg anime-19.jpg anime-22.jpg anime-4.jpg anime-8.jpg
# Note that files are sorted as 0, 1, 10, 11, 12, ... 19, 2, 20, 21, ...
# so, to convert it back, it is NOT as easy as
convert *.jpg out.gif
# above gave jerky animation due to wrong sequence of images
# we need:
convert `ls *.jpg | sort --version-sort` out.gif
# as expected, version sort gives 1, 2, 3, ... 10, 11, 12, ... 19, 20, 21, ...
# more control, for example:
convert -delay 10 -loop 0 `ls *.jpg | sort --version-sort` out10.gif
delay is 10 * 10ms ie. 1/10 sec per frame
loop 0 meaning no repeat
Labels: animated, gif, imagemagick, images